Skip to content

Commit

Permalink
Always update filter widgets with preset searchCols (rstudio#1115)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikmart authored and AhmedKhaled945 committed Feb 2, 2024
1 parent 0974d41 commit 53c23c7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 14 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

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

- The `searchCols` option now sets the slider values for numeric columns when `server = TRUE` (thanks, @alexvpickering, @mikmart, #998).

- Added server-side processing support for the [SearchBuilder](https://datatables.net/extensions/searchbuilder/) extension (thanks, @AhmedKhaled945, @shrektan, @mikmart, #963).

# CHANGES IN DT VERSION 0.31
Expand Down
17 changes: 3 additions & 14 deletions inst/htmlwidgets/datatables.js
Original file line number Diff line number Diff line change
Expand Up @@ -518,10 +518,7 @@ HTMLWidgets.widget({
table.draw(); // redraw table, and filters will be applied
}
});
if (searchCol) filter[0].selectize.setValue(JSON.parse(searchCol));
// an ugly hack to deal with shiny: for some reason, the onBlur event
// of selectize does not work in shiny
$x.find('div > div.selectize-input > input').on('blur', function() {
filter[0].selectize.on('blur', function() {
$x.hide().trigger('hide'); $input.parent().show(); $input.trigger('blur');
});
filter.next('div').css('margin-bottom', 'auto');
Expand Down Expand Up @@ -685,7 +682,7 @@ HTMLWidgets.widget({
// processing
if (server) {
// if a search string has been pre-set, search now
if (searchCol) searchColumn(i, searchCol).draw();
if (searchCol) $input.trigger('input').trigger('change');
return;
}

Expand Down Expand Up @@ -724,15 +721,7 @@ HTMLWidgets.widget({
$.fn.dataTable.ext.search.push(customFilter);

// search for the preset search strings if it is non-empty
if (searchCol) {
if (inArray(type, ['factor', 'logical'])) {
filter[0].selectize.setValue(JSON.parse(searchCol));
} else if (type === 'character') {
$input.trigger('input');
} else if (inArray(type, ['number', 'integer', 'date', 'time'])) {
$input.trigger('change');
}
}
if (searchCol) $input.trigger('input').trigger('change');

});

Expand Down

0 comments on commit 53c23c7

Please sign in to comment.