From 0287a5046c9d82735dc5d01f99dbbbb8eda5287c Mon Sep 17 00:00:00 2001 From: Mosk915 <59397359+Mosk915@users.noreply.github.com> Date: Mon, 25 Nov 2024 16:00:40 -0500 Subject: [PATCH 01/12] Add lazyRender to datatables.js --- inst/htmlwidgets/datatables.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/inst/htmlwidgets/datatables.js b/inst/htmlwidgets/datatables.js index 765b53cb..bc72a1c6 100644 --- a/inst/htmlwidgets/datatables.js +++ b/inst/htmlwidgets/datatables.js @@ -180,7 +180,9 @@ HTMLWidgets.widget({ }; }, renderValue: function(el, data, instance) { - if (el.offsetWidth === 0 || el.offsetHeight === 0) { + if(!data.hasOwnProperty("lazyRender")) + data.lazyRender = true; + if ((el.offsetWidth === 0 || el.offsetHeight === 0) && data.lazyRender) { instance.data = data; return; } From c6b9df69f75b7c0aac894380104017ee300222f0 Mon Sep 17 00:00:00 2001 From: Mosk915 <59397359+Mosk915@users.noreply.github.com> Date: Mon, 25 Nov 2024 16:03:01 -0500 Subject: [PATCH 02/12] Add lazyRender to datatables.R --- R/datatables.R | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/R/datatables.R b/R/datatables.R index 999aec14..2e4355bf 100644 --- a/R/datatables.R +++ b/R/datatables.R @@ -64,6 +64,8 @@ #' (only display the table body) when the number of total records is less #' than the page size. Note, it only works on the client-side processing mode #' and the `pageLength` option should be provided explicitly. +#' @param lazyRender \code{TRUE} to delay rendering until the table becomes visible +#' (the default) or \code{FALSE} to render the table immediately on page load. #' @param selection the row/column selection mode (single or multiple selection #' or disable selection) when a table widget is rendered in a Shiny app; #' alternatively, you can use a list of the form \code{list(mode = 'multiple', @@ -207,6 +209,7 @@ datatable = function( escape = TRUE, style = 'auto', width = NULL, height = NULL, elementId = NULL, fillContainer = getOption('DT.fillContainer', NULL), autoHideNavigation = getOption('DT.autoHideNavigation', NULL), + lazyRender = TRUE, selection = c('multiple', 'single', 'none'), extensions = list(), plugins = NULL, editable = FALSE ) { @@ -375,6 +378,9 @@ datatable = function( params$autoHideNavigation = autoHideNavigation } + # record lazyRender + params$lazyRender = lazyRender + params = structure(modifyList(params, list( data = data, container = as.character(container), options = options, callback = if (!missing(callback)) JS('function(table) {', callback, '}') From 17dc124fbec29b3400dadc718b0f930a966f02fb Mon Sep 17 00:00:00 2001 From: Mosk915 <59397359+Mosk915@users.noreply.github.com> Date: Mon, 25 Nov 2024 16:04:06 -0500 Subject: [PATCH 03/12] Add lazyRender to NEWS.md --- NEWS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/NEWS.md b/NEWS.md index 5e7e7277..c163497d 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,6 @@ # CHANGES IN DT VERSION 0.34 +- Added `lazyRender` parameter to `datatable`, which gives the option for the table to be rendered immediately rather than waiting for it to become visible (#1156). # CHANGES IN DT VERSION 0.33 From ecad392bec4ba2732c2a6a438afee66ca11527d0 Mon Sep 17 00:00:00 2001 From: Mosk915 <59397359+Mosk915@users.noreply.github.com> Date: Mon, 25 Nov 2024 17:43:26 -0500 Subject: [PATCH 04/12] Update NEWS.md Co-authored-by: Yihui Xie --- NEWS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index c163497d..9e65aba4 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,6 @@ # CHANGES IN DT VERSION 0.34 -- Added `lazyRender` parameter to `datatable`, which gives the option for the table to be rendered immediately rather than waiting for it to become visible (#1156). +- Added `lazyRender` parameter to `DT::datatable()`, which gives the option for the table to be rendered immediately rather than waiting for it to become visible (thanks, @Mosk915, #1156). # CHANGES IN DT VERSION 0.33 From ca352c629fedb6f846cb17c2ddd78acaef5b8d6f Mon Sep 17 00:00:00 2001 From: Mosk915 <59397359+Mosk915@users.noreply.github.com> Date: Mon, 25 Nov 2024 17:43:54 -0500 Subject: [PATCH 05/12] Update R/datatables.R Co-authored-by: Yihui Xie --- R/datatables.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/datatables.R b/R/datatables.R index 2e4355bf..66c7ba8c 100644 --- a/R/datatables.R +++ b/R/datatables.R @@ -209,7 +209,7 @@ datatable = function( escape = TRUE, style = 'auto', width = NULL, height = NULL, elementId = NULL, fillContainer = getOption('DT.fillContainer', NULL), autoHideNavigation = getOption('DT.autoHideNavigation', NULL), - lazyRender = TRUE, + lazyRender = NULL, selection = c('multiple', 'single', 'none'), extensions = list(), plugins = NULL, editable = FALSE ) { From f907b6f979d2dbee9ee0f7c28f0ff9d6604dffd1 Mon Sep 17 00:00:00 2001 From: Mosk915 <59397359+Mosk915@users.noreply.github.com> Date: Mon, 25 Nov 2024 17:44:09 -0500 Subject: [PATCH 06/12] Update R/datatables.R Co-authored-by: Yihui Xie --- R/datatables.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/datatables.R b/R/datatables.R index 66c7ba8c..aa02e74e 100644 --- a/R/datatables.R +++ b/R/datatables.R @@ -64,8 +64,8 @@ #' (only display the table body) when the number of total records is less #' than the page size. Note, it only works on the client-side processing mode #' and the `pageLength` option should be provided explicitly. -#' @param lazyRender \code{TRUE} to delay rendering until the table becomes visible -#' (the default) or \code{FALSE} to render the table immediately on page load. +#' @param lazyRender \code{FALSE} to render the table immediately on page load, +#' otherwise delay rendering until the table becomes visible. #' @param selection the row/column selection mode (single or multiple selection #' or disable selection) when a table widget is rendered in a Shiny app; #' alternatively, you can use a list of the form \code{list(mode = 'multiple', From b54927baf7ee613f0aea6dfa7c34af1809679795 Mon Sep 17 00:00:00 2001 From: Mosk915 <59397359+Mosk915@users.noreply.github.com> Date: Mon, 25 Nov 2024 17:44:28 -0500 Subject: [PATCH 07/12] Update inst/htmlwidgets/datatables.js Co-authored-by: Yihui Xie --- inst/htmlwidgets/datatables.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/inst/htmlwidgets/datatables.js b/inst/htmlwidgets/datatables.js index bc72a1c6..136a8b94 100644 --- a/inst/htmlwidgets/datatables.js +++ b/inst/htmlwidgets/datatables.js @@ -180,9 +180,7 @@ HTMLWidgets.widget({ }; }, renderValue: function(el, data, instance) { - if(!data.hasOwnProperty("lazyRender")) - data.lazyRender = true; - if ((el.offsetWidth === 0 || el.offsetHeight === 0) && data.lazyRender) { + if ((el.offsetWidth === 0 || el.offsetHeight === 0) && data.lazyRender !== false) { instance.data = data; return; } From 3d00b4cf39eab19ed2d0b08db9b95543c5835a99 Mon Sep 17 00:00:00 2001 From: Mosk915 <59397359+Mosk915@users.noreply.github.com> Date: Mon, 25 Nov 2024 17:49:40 -0500 Subject: [PATCH 08/12] Only write `lazyRender` to `params` if `FALSE` --- R/datatables.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/datatables.R b/R/datatables.R index aa02e74e..dd56f664 100644 --- a/R/datatables.R +++ b/R/datatables.R @@ -379,7 +379,7 @@ datatable = function( } # record lazyRender - params$lazyRender = lazyRender + if(isFALSE(lazyRender)) params$lazyRender = lazyRender params = structure(modifyList(params, list( data = data, container = as.character(container), options = options, From 6d21162b0eacf5355b66af0cdef08865c2b3226a Mon Sep 17 00:00:00 2001 From: Mosk915 <59397359+Mosk915@users.noreply.github.com> Date: Mon, 25 Nov 2024 17:57:37 -0500 Subject: [PATCH 09/12] roxygenize docs --- man/datatable.Rd | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/man/datatable.Rd b/man/datatable.Rd index a3bef5f9..f52bab7a 100644 --- a/man/datatable.Rd +++ b/man/datatable.Rd @@ -21,6 +21,7 @@ datatable( elementId = NULL, fillContainer = getOption("DT.fillContainer", NULL), autoHideNavigation = getOption("DT.autoHideNavigation", NULL), + lazyRender = NULL, selection = c("multiple", "single", "none"), extensions = list(), plugins = NULL, @@ -105,6 +106,9 @@ then vertical and/or horizontal scrolling of the table cells will occur.} than the page size. Note, it only works on the client-side processing mode and the `pageLength` option should be provided explicitly.} +\item{lazyRender}{\code{FALSE} to render the table immediately on page load, +otherwise delay rendering until the table becomes visible.} + \item{selection}{the row/column selection mode (single or multiple selection or disable selection) when a table widget is rendered in a Shiny app; alternatively, you can use a list of the form \code{list(mode = 'multiple', From 4f73f5eb1bc1b37f871623cde0b1fa89e06b0329 Mon Sep 17 00:00:00 2001 From: Yihui Xie Date: Mon, 25 Nov 2024 17:03:26 -0600 Subject: [PATCH 10/12] no need to test isFALSE() [ci skip] --- R/datatables.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/datatables.R b/R/datatables.R index dd56f664..30950661 100644 --- a/R/datatables.R +++ b/R/datatables.R @@ -379,7 +379,7 @@ datatable = function( } # record lazyRender - if(isFALSE(lazyRender)) params$lazyRender = lazyRender +params$lazyRender = lazyRender params = structure(modifyList(params, list( data = data, container = as.character(container), options = options, From 218a4d5e02760cec726a5d54032f57c41b2f2cdf Mon Sep 17 00:00:00 2001 From: Yihui Xie Date: Mon, 25 Nov 2024 17:04:06 -0600 Subject: [PATCH 11/12] bump version [ci skip] --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index e8408f24..3f78633b 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: DT Type: Package Title: A Wrapper of the JavaScript Library 'DataTables' -Version: 0.33.1 +Version: 0.33.2 Authors@R: c( person("Yihui", "Xie", role = "aut"), person("Joe", "Cheng", email = "joe@posit.co", role = c("aut", "cre")), From 74458d92d5824eeb4b0268b1acdd5fdf031c433b Mon Sep 17 00:00:00 2001 From: Yihui Xie Date: Mon, 25 Nov 2024 17:04:51 -0600 Subject: [PATCH 12/12] indent [ci skip] --- R/datatables.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/datatables.R b/R/datatables.R index 30950661..aa02e74e 100644 --- a/R/datatables.R +++ b/R/datatables.R @@ -379,7 +379,7 @@ datatable = function( } # record lazyRender -params$lazyRender = lazyRender + params$lazyRender = lazyRender params = structure(modifyList(params, list( data = data, container = as.character(container), options = options,