How can I filter a table
if at least one cell is filled, leave
if all cells are null then remove the row
[
[ 1, 2],
[3, null],
[null, 4],
[null, null],
[5, null],
[6, 7],
[null, null],
[9, null],
]
after filter want to see
[
[1, 2],
[3, null],
[null, 4],
[5, null],
[6, 7],
[9, null],
]
Hi @denis.safib
Filtering works per column, and here I see that you’d want to remove all the records that have null
in both of the columns. In this case, you should add an additional condition. What is the desired way to filter out those records
- should be an option in the column menu
dropdownMenu
- should filter out on initialization
- should be triggered by an outside element like a button or a checkbox
based on the answer, I can help you to create such a condition.
No need above the column i have a select element and a function that matches the condition
show ‘all’, ‘a t least one filled’ and 'empty’Н
const instance = this.$refs.hotTable.hotInstance;
const filtersPlugin = instance.getPlugin(‘filters’);
switch (action) {
case controlTableFilterEnum.all: {
this.columnsStore.forEach((column, index) => {
filtersPlugin.clearConditions(index);
})
filtersPlugin.filter()
}
break;
case controlTableFilterEnum.filled:
this.columnsStore.forEach((column, index) => {
filtersPlugin.clearConditions(index);
filtersPlugin.addCondition(index, 'not_empty', [[null]], 'disjunction');
// filtersPlugin.addCondition(index, 'not_empty ', [[null]], 'conjunction');// not_empty // , 'disjunction'
})
filtersPlugin.filter();
break;
case controlTableFilterEnum.blank:
this.columnsStore.forEach((column, index) => {
filtersPlugin.clearConditions(index);
filtersPlugin.addCondition(index, 'empty', []);
})
filtersPlugin.filter();
break;
}
controlTableFilterEnum.filled
does not work
The Filters
plugin is connected to a column (as previously said), so in your case where you have your own UI for filtering, I would recommend using the hiddenRows
plugin instead.
If I see correctly you might be using React, so I created a React example https://jsfiddle.net/Lczb53ru/
I hope that it helps.