Skip to content

Commit

Permalink
Add lazyRender parameter (#1158)
Browse files Browse the repository at this point in the history
Co-authored-by: Yihui Xie <[email protected]>
  • Loading branch information
Mosk915 and yihui authored Nov 25, 2024
1 parent 4e63a46 commit def0cae
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 2 deletions.
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.

0 comments on commit def0cae

Please sign in to comment.