feat: Add not equals (!=) filter

This commit is contained in:
Faris Ansari 2019-04-03 23:10:00 +05:30
parent 9a5a0b66e8
commit 637d37deb8

View File

@ -88,6 +88,15 @@ function getFilterMethod(filter) {
.map(cell => cell.rowIndex);
},
notEquals(keyword, cells) {
return cells
.filter(cell => {
const value = parseFloat(cell.content);
return value !== keyword;
})
.map(cell => cell.rowIndex);
},
range(rangeValues, cells) {
return cells
.filter(cell => {
@ -110,6 +119,8 @@ function guessFilter(keyword = '') {
if (['>', '<', '='].includes(compareString[0])) {
compareString = keyword.slice(1);
} else if (compareString.startsWith('!=')) {
compareString = keyword.slice(2);
}
if (keyword.startsWith('>')) {
@ -139,6 +150,15 @@ function guessFilter(keyword = '') {
}
}
if (keyword.startsWith('!=')) {
if (isNumber(compareString)) {
return {
type: 'notEquals',
text: Number(keyword.slice(2).trim())
};
}
}
if (keyword.split(':').length === 2) {
compareString = keyword.split(':');
return {