且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

列的条件格式化

更新时间:2022-12-15 16:15:16

datatable(mydf, options = list(columnDefs = list(list(
    targets = 0, render = JS(
        "function(data, type, full, meta) {",
            "italic_words=['ABC','JKL']",
            "return type === 'display' && italic_words.indexOf(data) != -1 ?",
            "'<i>'+data+'</i>' : data;",
        "}")
))))

我在javascript函数中定义了italic_words变量。该变量包含所有要使用的斜体字的数组。然后我使用indexOf()javascript函数。如果名称不在变量italic_words中,则此函数将返回-1,名称将不会被斜体显示。

I defined the italic_words variable in the javascript function. The variable contains an array of all the words you want in italic. Then I used the indexOf() javascript function. If the name isn't in the variable italic_words, this function will return -1, and the name will not be italicized.