Reputation: 51
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).
I'm trying to use this function (From this question), but all my table is italic starting from 3rd column. How can I fix it? (suppose, that my for loop is incorrect)
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)'});",
" }",
" }",
"}"
)
}
Upvotes: 1
Views: 304
Reputation: 84719
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.
$('td:eq('+j+')', row)
selects the j-th element of the current row, so you don't have to loop over rows.
Upvotes: 1