fix: 🐛 Filter rows based on the formatted value
Earlier filtering was done based on the original value of the cell, but formatters could change the display value
This commit is contained in:
parent
33f7ab9c25
commit
ec08d75261
File diff suppressed because one or more lines are too long
@ -792,6 +792,8 @@ export default class CellManager {
|
|||||||
contentHTML = customFormatter(cell.content, row, cell.column, data);
|
contentHTML = customFormatter(cell.content, row, cell.column, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cell.html = contentHTML;
|
||||||
|
|
||||||
if (this.options.treeView && !(isHeader || isFilter) && cell.indent !== undefined) {
|
if (this.options.treeView && !(isHeader || isFilter) && cell.indent !== undefined) {
|
||||||
const nextRow = this.datamanager.getRow(cell.rowIndex + 1);
|
const nextRow = this.datamanager.getRow(cell.rowIndex + 1);
|
||||||
const addToggle = nextRow && nextRow.meta.indent > cell.indent;
|
const addToggle = nextRow && nextRow.meta.indent > cell.indent;
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import { isNumber } from './utils';
|
import { isNumber, stripHTML } from './utils';
|
||||||
|
|
||||||
export default function filterRows(rows, filters) {
|
export default function filterRows(rows, filters) {
|
||||||
let filteredRowIndices = [];
|
let filteredRowIndices = [];
|
||||||
@ -30,7 +30,7 @@ function getFilterMethod(filter) {
|
|||||||
contains(keyword, cells) {
|
contains(keyword, cells) {
|
||||||
return cells
|
return cells
|
||||||
.filter(cell => {
|
.filter(cell => {
|
||||||
const hay = String(cell.content || '').toLowerCase();
|
const hay = String(stripHTML(cell.html) || '').toLowerCase();
|
||||||
const needle = (keyword || '').toLowerCase();
|
const needle = (keyword || '').toLowerCase();
|
||||||
return !needle || hay.includes(needle);
|
return !needle || hay.includes(needle);
|
||||||
})
|
})
|
||||||
@ -40,7 +40,7 @@ function getFilterMethod(filter) {
|
|||||||
greaterThan(keyword, cells) {
|
greaterThan(keyword, cells) {
|
||||||
return cells
|
return cells
|
||||||
.filter(cell => {
|
.filter(cell => {
|
||||||
const value = Number(cell.content);
|
const value = Number(stripHTML(cell.html));
|
||||||
return value > keyword;
|
return value > keyword;
|
||||||
})
|
})
|
||||||
.map(cell => cell.rowIndex);
|
.map(cell => cell.rowIndex);
|
||||||
@ -49,7 +49,7 @@ function getFilterMethod(filter) {
|
|||||||
lessThan(keyword, cells) {
|
lessThan(keyword, cells) {
|
||||||
return cells
|
return cells
|
||||||
.filter(cell => {
|
.filter(cell => {
|
||||||
const value = Number(cell.content);
|
const value = Number(stripHTML(cell.html));
|
||||||
return value < keyword;
|
return value < keyword;
|
||||||
})
|
})
|
||||||
.map(cell => cell.rowIndex);
|
.map(cell => cell.rowIndex);
|
||||||
@ -58,7 +58,7 @@ function getFilterMethod(filter) {
|
|||||||
range(rangeValues, cells) {
|
range(rangeValues, cells) {
|
||||||
return cells
|
return cells
|
||||||
.filter(cell => {
|
.filter(cell => {
|
||||||
const value = Number(cell.content);
|
const value = Number(stripHTML(cell.html));
|
||||||
return value >= rangeValues[0] && value <= rangeValues[1];
|
return value >= rangeValues[0] && value <= rangeValues[1];
|
||||||
})
|
})
|
||||||
.map(cell => cell.rowIndex);
|
.map(cell => cell.rowIndex);
|
||||||
|
|||||||
@ -134,3 +134,7 @@ export function uniq(arr) {
|
|||||||
export function numberSortAsc(a, b) {
|
export function numberSortAsc(a, b) {
|
||||||
return a - b;
|
return a - b;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export function stripHTML(html) {
|
||||||
|
return html.replace(/<[^>]*>/g, '');
|
||||||
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user