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 #1157

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 `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

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{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',
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 = TRUE,
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
4 changes: 3 additions & 1 deletion inst/htmlwidgets/datatables.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Loading