Skip to content

Conversation

@pedropark99
Copy link
Contributor

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)
  }

@CLAassistant
Copy link

CLAassistant commented Sep 27, 2023

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

@yihui yihui left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. It will be great to add a NEWS item to NEWS.md. Thanks!

@yihui yihui linked an issue Sep 28, 2023 that may be closed by this pull request
@pedropark99
Copy link
Contributor Author

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 😉

@yihui yihui merged commit 65e6169 into rstudio:main Oct 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

DataTable class list options don't work with style = 'bootstrap'

3 participants