This PR seeks to bring support for a list of classes in DT2BSClass(), with the end goal of fixing the issue #1052.
In more details, when you select style='bootstrap', DT::datatable() tries to translate the class argument, to a css rule with all the Bootstrap classes that were mentioned in the class argument. To make this translation, the DT2BSClass() function is called with the class argument. However, the DT2BSClass() function only supports a character vector as input.
This PR will allow DT2BSClass() to receive a list of booleans as input, as mentioned in the example from issue #1052.
# Now these examples below works
DT::datatable(mtcars, class=list(stripe=F), style = "bootstrap")
DT::datatable(mtcars, class=list(stripe=T, compact=F, hover=T), style = "bootstrap")
In essence, we use base::Filter() to select the elements of the list that are TRUE, and simply extract the name of these filtered elements.
if (is.list(class)) {
chosen_classes = Filter(function(x) isTRUE(x), class)
class = names(chosen_classes)
}
Thank you @yihui for the review! I updated NEWS.md with the changes, and, also changed the source code to use which() instead of Filter() as you suggested 😉
This PR seeks to bring support for a list of classes in
DT2BSClass()
, with the end goal of fixing the issue #1052.In more details, when you select
style='bootstrap'
,DT::datatable()
tries to translate theclass
argument, to a css rule with all the Bootstrap classes that were mentioned in theclass
argument. To make this translation, theDT2BSClass()
function is called with the class argument. However, theDT2BSClass()
function only supports a character vector as input.This PR will allow
DT2BSClass()
to receive a list of booleans as input, as mentioned in the example from issue #1052.In essence, we use
base::Filter()
to select the elements of the list that are TRUE, and simply extract the name of these filtered elements.