Browse Source

769 refine empty nonempty operators logic

pull/784/head
koalyptus 1 year ago
parent
commit
825b915ae8
  1. 2
      .eslintrc
  2. 4
      dist/starter.html
  3. 2
      dist/tablefilter/tablefilter.js
  4. 2
      package.json
  5. 8
      src/tablefilter.js
  6. 11
      test/test-filter-operators.js

2
.eslintrc

@ -14,7 +14,7 @@
"keyword-spacing": ["error", { "after": true, "before": true }],
"max-depth": [2, 7],
"max-statements": [2, 133],
"complexity": [2, 42],
"complexity": [2, 45],
"no-unused-vars": 2,
"no-eval": 2,
"no-underscore-dangle": 0,

4
dist/starter.html

@ -1,10 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>tablefilter v0.7.1 - Starter</title>
<title>tablefilter v0.7.2 - Starter</title>
</head>
<body>
<h1>tablefilter v0.7.1</h1>
<h1>tablefilter v0.7.2</h1>

2
dist/tablefilter/tablefilter.js

File diff suppressed because one or more lines are too long

2
package.json

@ -1,6 +1,6 @@
{
"name": "tablefilter",
"version": "0.7.1",
"version": "0.7.2",
"description": "A Javascript library making HTML tables filterable and a bit more",
"license": "MIT",
"author": {

8
src/tablefilter.js

@ -1785,11 +1785,11 @@ export class TableFilter {
}
//empty
else if (hasEM) {
occurence = !cell.hasChildNodes();
occurence = !cell.hasChildNodes() || isEmpty(cellValue);
}
//non-empty
else if (hasNM) {
occurence = cell.hasChildNodes();
occurence = cell.hasChildNodes() && !isEmpty(cellValue);
} else {
occurence = contains(term, cellValue,
this.isExactMatch(colIdx), this.caseSensitive);
@ -1875,11 +1875,11 @@ export class TableFilter {
}
//empty
else if (hasEM) {
occurence = !cell.hasChildNodes();
occurence = !cell.hasChildNodes() || isEmpty(cellValue);
}
//non-empty
else if (hasNM) {
occurence = cell.hasChildNodes();
occurence = cell.hasChildNodes() && !isEmpty(cellValue);
} else {
// If numeric type data, perform a strict equality test and
// fallback to unformatted number string comparison

11
test/test-filter-operators.js

@ -72,7 +72,14 @@
tf.clearFilters();
tf.setFilterValue(4, '[empty]');
tf.filter();
deepEqual(tf.getValidRows().length, 0, 'No matches expected');
var filteredData = tf.getFilteredData();
deepEqual(tf.getValidRows().length, 1, 'Expected match');
deepEqual(
filteredData[0],
[6, ['Adelaide', 'Perth', '2781', '3.1', '']],
'Expected row data'
);
});
test('Non-empty operator - [nonempty]', function() {
@ -96,7 +103,7 @@
tf.setFilterValue(4, '[nonempty]');
tf.filter();
deepEqual(tf.getValidRows().length, 7, 'Expected number of matches');
deepEqual(tf.getValidRows().length, 6, 'Expected number of matches');
});
test('Or operator - ||', function() {

Loading…
Cancel
Save