Search code examples
rdt

Datatable multiple class options: nowrap text and no row shading


I am trying to pass different class options to datatable in my Shiny app (https://datatables.net/manual/styling/classes).

In particular, I want no wrapping of cell content, and avoid alternate row shading.

I can accomplish this separately:

datatable(mydata, class = "display nowrap")

or

datatable(mydata, class = list(stripe = FALSE))

but I cannot make them work together. I tried all the following options, with no success (no error, just one of the two things won't work):

datatable(mydata, class = list("display nowrap", stripe = FALSE))
datatable(mydata, class = list("display nowrap", list(stripe = FALSE)))
datatable(mydata, class = list(nowrap = TRUE, stripe = FALSE))
datatable(mydata, class = "display nowrap", class = list(stripe = FALSE))

Is there a way to pass multiple class options?


Solution

  • Attempts like datatable(mydata, class = list("display nowrap", stripe = FALSE)) can't work because with display you implicitly also set stripe. From the docs:

    display: Short-hand for the stripe, hover, row-border and order-column classes.

    So if you wan't to have nowrap, no stripe and everything else which comes from display, you could set the class like this:

    datatable(mydata, class = "hover row-border order-column nowrap")