[英]JavaScript function for DT formatting (R shiny)
I need to design the R Shiny data table, using Java Script like that (like stairs on the DT bottom, which shows the prediction values - italic and gray).我需要设计 R Shiny 数据表,使用类似的 Java 脚本(如 DT 底部的楼梯,显示预测值 -斜体和灰色)。
I'm trying to use this function ( From this question ), but all my table is italic starting from 3rd column.我正在尝试使用此功能( 来自此问题),但我的所有表格从第 3 列开始都是斜体。 How can I fix it?
我该如何解决? (suppose, that my for loop is incorrect)
(假设我的 for 循环不正确)
rowCallback <- function(rows){
c(
"function(row, data, num){",
sprintf(" var rows = [%s];", paste0(rows-1, collapse = ",")),
" for(let j=data.length; j >= 3; j--){",
" for(let i=j; i<data.length; i++){",
" $('td:eq('+i+')', row)",
" .css({'background-color': 'rgb(211,211,211)', 'font-style': 'italic', 'font-color': 'rgb(230,230,230)'});",
" }",
" }",
"}"
)
} }
Not tested, I would try:未经测试,我会尝试:
rowCallback <- c(
"function(row, data, num, index){",
" var ncols = data.length;",
" for(let j=ncols; j > ncols-index; j--){",
" $('td:eq('+j+')', row)",
" .css({'background-color': 'rgb(211,211,211)', 'font-style': 'italic', 'font-color': 'rgb(230,230,230)'});",
" }",
"}"
)
Notes:笔记:
You don't need a R function, because the rows
argument is not used.您不需要 R 函数,因为未使用
rows
参数。
$('td:eq('+j+')', row)
selects the j-th element of the current row, so you don't have to loop over rows. $('td:eq('+j+')', row)
选择当前行的第 j 个元素,因此您不必遍历行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.