Skip to content

Commit

Permalink
fix #1108: when data in replaceData() has no column names, assume i…
Browse files Browse the repository at this point in the history
…t is not reordered, and will not be

this assumption is not necessarily true, but there's nothing we could do if users want to reorder columns when column names are not provided
  • Loading branch information
yihui committed Jan 18, 2024
1 parent 487dc08 commit 33b7642
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 1 deletion.
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.31.1
Version: 0.31.2
Authors@R: c(
person("Yihui", "Xie", email = "[email protected]", role = c("aut", "cre")),
person("Joe", "Cheng", role = "aut"),
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.32

- Fixed the bug that `replaceData()` failed to work with data that has no column names (thanks, @mmuurr, #1108).

# CHANGES IN DT VERSION 0.31

Expand Down
6 changes: 6 additions & 0 deletions R/shiny.R
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,9 @@ reloadData = function(
#' levels, and numeric columns should have the same or smaller range,
#' otherwise the filters may never be able to reach certain rows in the data,
#' unless you explicitly update the filters with \code{updateFilters()}.
#'
#' If the \code{ColReorder} extension is used, the new \code{data} must have
#' column names that match the original data column names exactly.
#' @export
replaceData = function(proxy, data, ..., resetPaging = TRUE, clearSelection = 'all') {
dataTableAjax(proxy$session, data, ..., outputId = proxy$rawId)
Expand Down Expand Up @@ -618,6 +621,9 @@ dataTablesFilter = function(data, params) {
# index in data via its name because the two indices won't match when columns
# are reordered via the colReorder extension
imap = unlist(lapply(q$columns, function(col) {
# if data doesn't have column names (e.g., #1108), assume it's not reordered
# (which may not be true)
if (is.null(names(data))) return(0L)
k = col[['name']]
if (!is.character(k) || k == '') return(0L)
i = match(k, names(data))
Expand Down
3 changes: 3 additions & 0 deletions man/replaceData.Rd

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

0 comments on commit 33b7642

Please sign in to comment.