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