feat: 🎸 Support for multiple filters in columns
Multiple inline filters will be applied as AND filters
This commit is contained in:
parent
ffe0d2a3f5
commit
932afb6cbe
@ -270,18 +270,19 @@ export default class ColumnManager {
|
||||
|
||||
bindFilter() {
|
||||
if (!this.options.inlineFilters) return;
|
||||
this.appliedFilters = this.appliedFilters || {};
|
||||
const handler = e => {
|
||||
this.$filterCell = $.closest('.dt-cell', e.target);
|
||||
const { colIndex } = $.data(this.$filterCell);
|
||||
const keyword = e.target.value;
|
||||
|
||||
this.applyFilter(keyword, colIndex);
|
||||
this.appliedFilters[colIndex] = keyword;
|
||||
this.applyFilter(this.appliedFilters);
|
||||
};
|
||||
$.on(this.header, 'keydown', '.dt-filter', debounce(handler, 300));
|
||||
}
|
||||
|
||||
applyFilter(keyword, colIndex) {
|
||||
this.datamanager.filterRows(keyword, colIndex)
|
||||
applyFilter(filters) {
|
||||
this.datamanager.filterRows(filters)
|
||||
.then(({
|
||||
rowsToShow
|
||||
}) => {
|
||||
|
||||
@ -422,10 +422,8 @@ export default class DataManager {
|
||||
return column;
|
||||
}
|
||||
|
||||
filterRows(keyword, colIndex) {
|
||||
const cells = this.rows.map(row => row[colIndex]);
|
||||
|
||||
return this.options.filterRows(keyword, cells, colIndex)
|
||||
filterRows(filters) {
|
||||
return this.options.filterRows(this.rows, filters)
|
||||
.then(result => {
|
||||
if (!result) {
|
||||
result = this.getAllRowIndices();
|
||||
|
||||
@ -1,14 +1,28 @@
|
||||
import { isNumber } from './utils';
|
||||
|
||||
export default function filterRows(keyword, cells, colIndex) {
|
||||
let filter = guessFilter(keyword);
|
||||
let filterMethod = getFilterMethod(filter);
|
||||
export default function filterRows(rows, filters) {
|
||||
let filteredRowIndices = [];
|
||||
|
||||
if (filterMethod) {
|
||||
return filterMethod(filter.text, cells);
|
||||
for (let colIndex in filters) {
|
||||
const keyword = filters[colIndex];
|
||||
|
||||
const filteredRows = filteredRowIndices.length ?
|
||||
filteredRowIndices.map(i => rows[i]) :
|
||||
rows;
|
||||
|
||||
const cells = filteredRows.map(row => row[colIndex]);
|
||||
|
||||
let filter = guessFilter(keyword);
|
||||
let filterMethod = getFilterMethod(filter);
|
||||
|
||||
if (filterMethod) {
|
||||
filteredRowIndices = filterMethod(filter.text, cells);
|
||||
} else {
|
||||
filteredRowIndices = cells.map(cell => cell.rowIndex);
|
||||
}
|
||||
}
|
||||
|
||||
return cells.map(cell => cell.rowIndex);
|
||||
return filteredRowIndices;
|
||||
};
|
||||
|
||||
function getFilterMethod(filter) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user