mirror of
https://github.com/koalyptus/TableFilter.git
synced 2024-06-08 00:42:28 +02:00
refine empty-nonempty operator checks
This commit is contained in:
parent
50afb94340
commit
efffa40248
4
dist/starter.html
vendored
4
dist/starter.html
vendored
|
@ -1,10 +1,10 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<title>tablefilter v0.6.42 - Starter</title>
|
||||
<title>tablefilter v0.6.50 - Starter</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>tablefilter v0.6.42</h1>
|
||||
<h1>tablefilter v0.6.50</h1>
|
||||
|
||||
|
||||
|
||||
|
|
2
dist/tablefilter/tablefilter.js
vendored
2
dist/tablefilter/tablefilter.js
vendored
File diff suppressed because one or more lines are too long
2
dist/tablefilter/tablefilter.js.map
vendored
2
dist/tablefilter/tablefilter.js.map
vendored
File diff suppressed because one or more lines are too long
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "tablefilter",
|
||||
"version": "0.6.49",
|
||||
"version": "0.6.50",
|
||||
"description": "A Javascript library making HTML tables filterable and a bit more",
|
||||
"license": "MIT",
|
||||
"author": {
|
||||
|
|
|
@ -4,7 +4,6 @@ import {
|
|||
removeClass, tag
|
||||
} from './dom';
|
||||
import {contains, matchCase, rgxEsc, trim} from './string';
|
||||
import {isEmpty as isEmptyString} from './string';
|
||||
import {
|
||||
isArray, isEmpty, isFn, isNumber, isObj, isString, isUndef, EMPTY_FN,
|
||||
isBoolean
|
||||
|
@ -1623,7 +1622,7 @@ export class TableFilter {
|
|||
// isolate search term and check occurence in cell data
|
||||
for (let w = 0, len = s.length; w < len; w++) {
|
||||
cS = trim(s[w]);
|
||||
found = this._match(cS, cellValue, j);
|
||||
found = this._match(cS, cellValue, cells[j]);
|
||||
|
||||
if (found) {
|
||||
emitter.emit('highlight-keyword', this,
|
||||
|
@ -1642,7 +1641,8 @@ export class TableFilter {
|
|||
}
|
||||
//single search parameter
|
||||
else {
|
||||
occurence[j] = this._match(trim(sA), cellValue, j);
|
||||
occurence[j] =
|
||||
this._match(trim(sA), cellValue, cells[j]);
|
||||
if (occurence[j]) {
|
||||
emitter.emit('highlight-keyword', this, cells[j],
|
||||
sA);
|
||||
|
@ -1688,14 +1688,15 @@ export class TableFilter {
|
|||
|
||||
/**
|
||||
* Match search term in cell data
|
||||
* @param {String} term Search term
|
||||
* @param {String} term Search term
|
||||
* @param {String} cellValue Cell data
|
||||
* @param {Number} colIdx Column index
|
||||
* @param {DOMElement} cell Current cell
|
||||
* @return {Boolean}
|
||||
* @private
|
||||
*/
|
||||
_match(term, cellValue, colIdx) {
|
||||
_match(term, cellValue, cell) {
|
||||
let numData;
|
||||
let colIdx = cell.cellIndex;
|
||||
let decimal = this.getDecimal(colIdx);
|
||||
let reLe = new RegExp(this.leOperator),
|
||||
reGe = new RegExp(this.geOperator),
|
||||
|
@ -1797,11 +1798,11 @@ export class TableFilter {
|
|||
}
|
||||
//empty
|
||||
else if (hasEM) {
|
||||
occurence = isEmptyString(cellValue);
|
||||
occurence = !cell.hasChildNodes();
|
||||
}
|
||||
//non-empty
|
||||
else if (hasNM) {
|
||||
occurence = !isEmptyString(cellValue);
|
||||
occurence = cell.hasChildNodes();
|
||||
} else {
|
||||
occurence = contains(term, cellValue,
|
||||
this.isExactMatch(colIdx), this.caseSensitive);
|
||||
|
@ -1887,11 +1888,11 @@ export class TableFilter {
|
|||
}
|
||||
//empty
|
||||
else if (hasEM) {
|
||||
occurence = isEmptyString(cellValue);
|
||||
occurence = !cell.hasChildNodes();
|
||||
}
|
||||
//non-empty
|
||||
else if (hasNM) {
|
||||
occurence = !isEmptyString(cellValue);
|
||||
occurence = cell.hasChildNodes();
|
||||
} else {
|
||||
// If numeric type data, perform a strict equality test and
|
||||
// fallback to unformatted number string comparison
|
||||
|
|
|
@ -51,10 +51,13 @@
|
|||
});
|
||||
|
||||
test('Empty operator - [empty]', function() {
|
||||
var cell = tf.getWorkingRows()[4].cells[4];
|
||||
cell.innerHTML = '';
|
||||
tf.clearFilters();
|
||||
tf.setFilterValue(4, '[empty]');
|
||||
tf.filter();
|
||||
var filteredData = tf.getFilteredData();
|
||||
|
||||
deepEqual(tf.getValidRows().length, 1, 'Expected number of matches');
|
||||
deepEqual(
|
||||
filteredData[0],
|
||||
|
@ -63,7 +66,18 @@
|
|||
);
|
||||
});
|
||||
|
||||
test('Empty operator - with cell containing dom element', function() {
|
||||
var cell = tf.getWorkingRows()[4].cells[4];
|
||||
cell.innerHTML = '<img>';
|
||||
tf.clearFilters();
|
||||
tf.setFilterValue(4, '[empty]');
|
||||
tf.filter();
|
||||
deepEqual(tf.getValidRows().length, 0, 'No matches expected');
|
||||
});
|
||||
|
||||
test('Non-empty operator - [nonempty]', function() {
|
||||
var cell = tf.getWorkingRows()[4].cells[4];
|
||||
cell.innerHTML = '';
|
||||
tf.clearFilters();
|
||||
tf.setFilterValue(4, '[nonempty]');
|
||||
tf.filter();
|
||||
|
@ -75,6 +89,18 @@
|
|||
'Expected row data');
|
||||
});
|
||||
|
||||
test('Non-empty operator - with cell containing dom element', function() {
|
||||
var cell = tf.getWorkingRows()[4].cells[4];
|
||||
cell.innerHTML = '<img>';
|
||||
tf.clearFilters();
|
||||
tf.setFilterValue(4, '[nonempty]');
|
||||
tf.filter();
|
||||
var filteredData = tf.getFilteredData();
|
||||
console.log(filteredData);
|
||||
|
||||
deepEqual(tf.getValidRows().length, 7, 'Expected number of matches');
|
||||
});
|
||||
|
||||
test('Or operator - ||', function() {
|
||||
tf.clearFilters();
|
||||
tf.setFilterValue(1, 'Canberra||Alice Springs');
|
||||
|
|
Loading…
Reference in a new issue