From 560e5b0f8f0e2b08e3d0cc86cf8d25e1b37aecd0 Mon Sep 17 00:00:00 2001 From: Yihui Xie Date: Wed, 24 Jan 2024 23:36:49 -0600 Subject: [PATCH] if filter$settings is not provided (i.e., NULL), just omit `filterSettings` 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 `{}`) --- DESCRIPTION | 2 +- R/datatables.R | 9 ++------- inst/htmlwidgets/datatables.js | 1 + man/datatable.Rd | 2 +- 4 files changed, 5 insertions(+), 9 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index f9bf8a8e..e93517cb 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -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 = "xie@yihui.name", role = c("aut", "cre")), person("Joe", "Cheng", role = "aut"), diff --git a/R/datatables.R b/R/datatables.R index 042419f1..999aec14 100644 --- a/R/datatables.R +++ b/R/datatables.R @@ -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 @@ -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) diff --git a/inst/htmlwidgets/datatables.js b/inst/htmlwidgets/datatables.js index fa1fc4e7..91d15494 100644 --- a/inst/htmlwidgets/datatables.js +++ b/inst/htmlwidgets/datatables.js @@ -438,6 +438,7 @@ HTMLWidgets.widget({ }; if (data.filter !== 'none') { + if (!data.hasOwnProperty('filterSettings')) data.filterSettings = {}; filterRow.each(function(i, td) { diff --git a/man/datatable.Rd b/man/datatable.Rd index 8b030a65..a3bef5f9 100644 --- a/man/datatable.Rd +++ b/man/datatable.Rd @@ -229,7 +229,7 @@ data frame) using the JavaScript library DataTables. 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