Skip to content

Commit

Permalink
fix #1082: when updating the search keywords, we need to trigger the …
Browse files Browse the repository at this point in the history
…'input' event so that the clear button can show up inside the input box; for a select input, we need to set the value of the corresponding selectize input so that its 'onChange' event can be triggered (hence updating the table)
  • Loading branch information
yihui committed Sep 2, 2023
1 parent 2948e75 commit b6de4ac
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 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.29.1
Version: 0.29.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.30

- Fixed a bug that when using `updateSearch()`, the clear button inside the input box doesn't show up, and the table doesn't update when the input is cleared (thanks, @DavidBlairs, #1082).

# CHANGES IN DT VERSION 0.29

Expand Down
6 changes: 4 additions & 2 deletions inst/htmlwidgets/datatables.js
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,9 @@ HTMLWidgets.widget({
$input.parent().hide(); $x.show().trigger('show'); filter[0].selectize.focus();
},
input: function() {
if ($input.val() === '') filter[0].selectize.setValue([]);
var v1 = JSON.stringify(filter[0].selectize.getValue()), v2 = $input.val();
if (v1 === '[]') v1 = '';
if (v1 !== v2) filter[0].selectize.setValue(v2 === '' ? [] : JSON.parse(v2));
}
});
var $input2 = $x.children('select');
Expand Down Expand Up @@ -1398,7 +1400,7 @@ HTMLWidgets.widget({
console.log('The search keyword for column ' + i + ' is undefined')
return;
}
$(td).find('input').first().val(v);
$(td).find('input').first().val(v).trigger('input');
searchColumn(i, v);
});
table.draw();
Expand Down

0 comments on commit b6de4ac

Please sign in to comment.