DT cell hover showing cell based sample sizes from hidden column

后端 未结 1 853
一向
一向 2020-12-22 03:05

I have previously asked how to colour cells based on colours stored in hidden columns (link). I saw that it is also possible to apply hover information for (DT) tables via t

相关标签:
1条回答
  • 2020-12-22 03:33

    You could simply add a rowcallback to option paramters to get the toopltip from hidden columns. Something like this:

    DT <- datatable(dat, 
                    options = list(columnDefs = list(list(visible=FALSE, targets = 6:10)), rowCallback = JS(
                      "function(nRow, aData, iDisplayIndex, iDisplayIndexFull) {",
                      "$('td:eq(1)', nRow).attr('title',aData[1+5]);",
                      "$('td:eq(2)', nRow).attr('title',aData[2+5]);",
                      "$('td:eq(3)', nRow).attr('title',aData[3+5]);",
                      "$('td:eq(4)', nRow).attr('title',aData[4+5]);",
                      "$('td:eq(5)', nRow).attr('title',aData[6+5]);",
                      "}")))
    

    [EDIT]:

    You can do the same thing in loop as follows:

    DT <- datatable(dat, 
                    options = list(columnDefs = list(list(visible=FALSE, targets = 6:10)), rowCallback = JS(
                      "function(nRow, aData, iDisplayIndex, iDisplayIndexFull) {",
                      'for(i=0; i<5; i++ ){',
                      "$('td:eq('+i+')', nRow).attr('title',aData[i+5]);",
                      '}',
                      "}")))
    

    Hope it helps!

    0 讨论(0)
提交回复
热议问题