Skip to content

Commit

Permalink
Update numeric slider values on updateSearch (#1111)
Browse files Browse the repository at this point in the history
Co-authored-by: Yihui Xie <xie@yihui.name>
  • Loading branch information
mikmart and yihui authored Jan 18, 2024
1 parent 33b7642 commit 8bf8fa4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 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.31.2
Version: 0.31.3
Authors@R: c(
person("Yihui", "Xie", email = "xie@yihui.name", role = c("aut", "cre")),
person("Joe", "Cheng", role = "aut"),
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

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

- `updateSearch()` now sets the slider values based on the new search string for numeric columns (thanks, @mikmart, #1110).

# CHANGES IN DT VERSION 0.31

- Upgraded DataTables version to 1.13.6 (thanks, @stla, #1091).
Expand Down
15 changes: 9 additions & 6 deletions inst/htmlwidgets/datatables.js
Original file line number Diff line number Diff line change
Expand Up @@ -530,10 +530,12 @@ HTMLWidgets.widget({
var fun = function() {
searchColumn(i, $input.val()).draw();
};
if (server) {
fun = $.fn.dataTable.util.throttle(fun, options.searchDelay);
}
$input.on('input', fun);
// throttle searching for server-side processing
var throttledFun = $.fn.dataTable.util.throttle(fun, options.searchDelay);
$input.on('input', function(e, immediate) {
// always bypass throttling when immediate = true (via the updateSearch method)
(immediate || !server) ? fun() : throttledFun();
});
} else if (inArray(type, ['number', 'integer', 'date', 'time'])) {
var $x0 = $x;
$x = $x0.children('div').first();
Expand Down Expand Up @@ -1402,8 +1404,9 @@ HTMLWidgets.widget({
console.log('The search keyword for column ' + i + ' is undefined')
return;
}
$(td).find('input').first().val(v).trigger('input');
searchColumn(i, v);
// Update column search string and values on linked filter widgets.
// 'input' for factor and char filters, 'change' for numeric filters.
$(td).find('input').first().val(v).trigger('input', [true]).trigger('change');
});
table.draw();
}
Expand Down

0 comments on commit 8bf8fa4

Please sign in to comment.