diff --git a/NEWS.md b/NEWS.md index 49aa79f2..f001c064 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,6 +2,12 @@ - Fixed a bug that when using `updateSearch()`, the clear button inside the input box doesn't show up, and the table doesn't update when the input is cleared (thanks, @DavidBlairs, #1082). +- Added support for a list of Booleans as input to the `class` argument of `DT::datatable()` when `style = 'bootstrap'` (thanks, @pedropark99, #1089). In other words, you can now select the Bootstrap classes you want to use at `DT::datatable()` by using a list of Booleans that select the classes you want to use. In the example below, we are producing an HTML table that uses the `stripe` and `hover` Bootstrap classes: + + ```r + DT::datatable(mtcars, class = list(stripe = TRUE, compact = FALSE, hover = TRUE), style = "bootstrap") + ``` + - Handle `NULL` return from `bslib::theme_version()` (thanks, @slodge-work, #1090). # CHANGES IN DT VERSION 0.29 diff --git a/R/datatables.R b/R/datatables.R index 3f6b539d..74436953 100644 --- a/R/datatables.R +++ b/R/datatables.R @@ -933,7 +933,11 @@ DTDependencies = function(style) { # translate DataTables classes to Bootstrap table classes DT2BSClass = function(class) { - class = unlist(strsplit(class, '\\s+')) + class = if (is.list(class)) { + names(which(unlist(class))) + } else { + unlist(strsplit(class, '\\s+')) + } if ('display' %in% class) class = unique(c('stripe', 'hover', 'row-border', 'order-column', class)) BSclass = c(