Skip to content

Commit

Permalink
if filter$settings is not provided (i.e., NULL), just omit `filterSet…
Browse files Browse the repository at this point in the history
…tings` in `params` so that this property will not be serialized into JSON (to save a few bytes); on the JS side, test if the property exists (if not, set it to `{}`)
  • Loading branch information
yihui committed Jan 25, 2024
1 parent 55d6fef commit 560e5b0
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 9 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: DT
Type: Package
Title: A Wrapper of the JavaScript Library 'DataTables'
Version: 0.31.3
Version: 0.31.4
Authors@R: c(
person("Yihui", "Xie", email = "[email protected]", role = c("aut", "cre")),
person("Joe", "Cheng", role = "aut"),
Expand Down
9 changes: 2 additions & 7 deletions R/datatables.R
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@
#' It defaults to \code{FALSE}.
#' \item \code{$opacity} is a numeric value between 0 and 1 used to set
#' the level of transparency of slider widgets. It defaults to \code{1}.
#' \item \code{$settings} is a named list used to directly pass configuration
#' \item \code{$settings} is a named list used to directly pass configuration
#' for initializing filter widgets in JavaScript.
#' \itemize{
#' \item The \code{$select} element is passed to the select widget, and
Expand Down Expand Up @@ -324,12 +324,7 @@ datatable = function(
params$filter = filter$position
params$vertical = filter$vertical
if (filter$position != 'none') params$filterHTML = filterHTML
params$filterSettings = filter$settings %||% list()
if (!is.list(params$filterSettings)) {
stop("`filter$settings` must be a named list.")
} else if (!all(names(params$filterSettings) %in% c('select', 'slider'))) {
stop("`filter$settings` must only contain `$select` or `$slider` elements.")
}
params$filterSettings = filter$settings

if (missing(container)) {
container = tags$table(tableHeader(colnames, escape), class = class)
Expand Down
1 change: 1 addition & 0 deletions inst/htmlwidgets/datatables.js
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,7 @@ HTMLWidgets.widget({
};

if (data.filter !== 'none') {
if (!data.hasOwnProperty('filterSettings')) data.filterSettings = {};

filterRow.each(function(i, td) {

Expand Down
2 changes: 1 addition & 1 deletion man/datatable.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 560e5b0

Please sign in to comment.