Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add lazyRender parameter #1158

Merged
merged 12 commits into from
Nov 25, 2024
Merged
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.33.1
Version: 0.33.2
Authors@R: c(
person("Yihui", "Xie", role = "aut"),
person("Joe", "Cheng", email = "[email protected]", role = c("aut", "cre")),
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# CHANGES IN DT VERSION 0.34

- 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

Expand Down
6 changes: 6 additions & 0 deletions R/datatables.R
Original file line number Diff line number Diff line change
Expand Up @@ -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{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',
Expand Down Expand Up @@ -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 = NULL,
selection = c('multiple', 'single', 'none'), extensions = list(), plugins = NULL,
editable = FALSE
) {
Expand Down Expand Up @@ -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, '}')
Expand Down
2 changes: 1 addition & 1 deletion inst/htmlwidgets/datatables.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ HTMLWidgets.widget({
};
},
renderValue: function(el, data, instance) {
if (el.offsetWidth === 0 || el.offsetHeight === 0) {
if ((el.offsetWidth === 0 || el.offsetHeight === 0) && data.lazyRender !== false) {
instance.data = data;
return;
}
Expand Down
4 changes: 4 additions & 0 deletions man/datatable.Rd

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