From 8bf8fa447e50eb4b47941551b835e9acba922ce4 Mon Sep 17 00:00:00 2001 From: Mikko Marttila <13412395+mikmart@users.noreply.github.com> Date: Thu, 18 Jan 2024 21:52:04 +0000 Subject: [PATCH] Update numeric slider values on updateSearch (#1111) Co-authored-by: Yihui Xie --- DESCRIPTION | 2 +- NEWS.md | 2 ++ inst/htmlwidgets/datatables.js | 15 +++++++++------ 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index b91146d3..f9bf8a8e 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -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"), diff --git a/NEWS.md b/NEWS.md index 24392537..9bb6da9b 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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). diff --git a/inst/htmlwidgets/datatables.js b/inst/htmlwidgets/datatables.js index d21dff0b..7442eed2 100644 --- a/inst/htmlwidgets/datatables.js +++ b/inst/htmlwidgets/datatables.js @@ -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(); @@ -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(); }