Skip to content

Commit

Permalink
fix the issue of one-sided numeric filters reported in #66
Browse files Browse the repository at this point in the history
  • Loading branch information
yihui committed May 6, 2015
1 parent 9f5f0e5 commit 8807207
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions inst/htmlwidgets/datatables.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,18 +141,21 @@ HTMLWidgets.widget({
if ($input.val() === '') filter.val([r1, r2]);
},
change: function() {
var v = $input.val();
var v = $input.val().replace(/\s/g, '');
if (v === '') return;
v = v.split('...');
if (v.length !== 2) {
$input.parent().addClass('has-error');
return;
}
if (v[0] === '') v[0] = null;
if (v[1] === '') v[1] = null;
$input.parent().removeClass('has-error');
// treat date as UTC time at midnight
var strTime = function(x) {
if (x === null) return null;
var s = type === 'date' ? 'T00:00:00Z' : '';
var t = new Date(x.replace(/\s/g, '') + s).getTime();
var t = new Date(x + s).getTime();
// add 10 minutes to date since it does not hurt the date, and
// it helps avoid the tricky floating point arithmetic problems,
// e.g. sometimes the date may be a few milliseconds earlier
Expand All @@ -163,7 +166,7 @@ HTMLWidgets.widget({
v[0] = strTime(v[0]);
v[1] = strTime(v[1]);
}
filter.val([+v[0], +v[1]]);
filter.val(v);
}
});
var formatDate = function(d) {
Expand Down

0 comments on commit 8807207

Please sign in to comment.