diff --git a/src/columnmanager.js b/src/columnmanager.js index 1cefd6e..7e7b909 100644 --- a/src/columnmanager.js +++ b/src/columnmanager.js @@ -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 }) => { diff --git a/src/datamanager.js b/src/datamanager.js index 44487a1..c179a6c 100644 --- a/src/datamanager.js +++ b/src/datamanager.js @@ -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(); diff --git a/src/filterRows.js b/src/filterRows.js index fec0831..8e11689 100644 --- a/src/filterRows.js +++ b/src/filterRows.js @@ -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) {