Skip to content

Commit 6c6fa73

Browse files
author
COMZM
committed
Add lazyRender parameter
1 parent 4e63a46 commit 6c6fa73

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# CHANGES IN DT VERSION 0.34
22

3+
- 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).
34

45
# CHANGES IN DT VERSION 0.33
56

R/datatables.R

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@
6464
#' (only display the table body) when the number of total records is less
6565
#' than the page size. Note, it only works on the client-side processing mode
6666
#' and the `pageLength` option should be provided explicitly.
67+
#' @param lazyRender \code{TRUE} to delay rendering until the table becomes visible
68+
#' (the default) or \code{FALSE} to render the table immediately on page load.
6769
#' @param selection the row/column selection mode (single or multiple selection
6870
#' or disable selection) when a table widget is rendered in a Shiny app;
6971
#' alternatively, you can use a list of the form \code{list(mode = 'multiple',
@@ -207,6 +209,7 @@ datatable = function(
207209
escape = TRUE, style = 'auto', width = NULL, height = NULL, elementId = NULL,
208210
fillContainer = getOption('DT.fillContainer', NULL),
209211
autoHideNavigation = getOption('DT.autoHideNavigation', NULL),
212+
lazyRender = TRUE,
210213
selection = c('multiple', 'single', 'none'), extensions = list(), plugins = NULL,
211214
editable = FALSE
212215
) {
@@ -375,6 +378,9 @@ datatable = function(
375378
params$autoHideNavigation = autoHideNavigation
376379
}
377380

381+
# record lazyRender
382+
params$lazyRender = lazyRender
383+
378384
params = structure(modifyList(params, list(
379385
data = data, container = as.character(container), options = options,
380386
callback = if (!missing(callback)) JS('function(table) {', callback, '}')

inst/htmlwidgets/datatables.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,9 @@ HTMLWidgets.widget({
180180
};
181181
},
182182
renderValue: function(el, data, instance) {
183-
if (el.offsetWidth === 0 || el.offsetHeight === 0) {
183+
if (!data.hasOwnProperty("lazyRender"))
184+
data.lazyRender = true;
185+
if ((el.offsetWidth === 0 || el.offsetHeight === 0) && data.lazyRender) {
184186
instance.data = data;
185187
return;
186188
}

0 commit comments

Comments
 (0)