renderDataTable选择包含值为>的所有单元格10并突出显示 [英] renderDataTable Select all cells containing value > 10 and highlight
问题描述
我正在创建一个dataTable,它具有用户定义的行数&列。我想循环遍历表中的所有单元格(减去第一列,其中包含名称),如果值大于10,则突出显示/更改CSS。Shiny有一个很好的示例来定位特定列(见下文)。我假设我需要编写一些jQuery函数?我是一个完整的jQuery新手,所以我试了一下,它显然没有奏效(也见下文)。任何帮助将不胜感激!
针对特定列的亮点示例:
rowCallback = I(
'function(row,data){
//第一列中的> = 5的粗体单元
if(parseFloat(data [0] )> = 5.0)
$(td:eq(0),row).css(font-weight,bold);
}'
)
我尝试编写一个函数来循环访问单元格:
$ $ $ $ $ $ {
$($,$,$)$ {
} (data [i])> 10.0)
$(td:eq(i),row).css(color,red);}
}')
管理实现它(不安装DT):
rowCallback = I(
'function(row,data){
$(td,row) .each(function(i){
if(i == 0)return; //第一列是行名
if(parseFloat(data [i])> = 10.0)
$(this).css(color,red);
});
}'
)
I'm creating a dataTable that has a user-defined number of rows & columns. I would like to loop through all of the cells in the table (minus the first column, which contains names) and highlight/change CSS if values are greater than 10. Shiny has a great example of targeting a specific column (see below). I'm assuming I'd need to write some sort of jQuery function? I'm a complete jQuery newbie, so I gave it a try, and, it obviously hasn't worked (also see below). Any help would be greatly appreciated!
Shiny example of targeting a specific column:
rowCallback = I(
'function(row, data) {
// Bold cells for those >= 5 in the first column
if (parseFloat(data[0]) >= 5.0)
$("td:eq(0)", row).css("font-weight", "bold");
}'
)
My failed attempt at writing a function to loop through cells:
rowCallback = I('
function(row, data) {
for each (i in 1:1000) {
if (parseFloat(data[i]) > 10.0)
$("td:eq(i)", row).css("color", "red");}
}')
Managed to implement it with this (without installing DT):
rowCallback = I(
'function(row, data) {
$("td", row).each(function(i) {
if (i == 0) return; // first column is row names
if (parseFloat(data[i]) >= 10.0)
$(this).css("color", "red");
});
}'
)
这篇关于renderDataTable选择包含值为>的所有单元格10并突出显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!