[GH #6558] Cancel filter effect

Tags: #<Tag:0x00007efc61621bc8> #<Tag:0x00007efc61621a88>

Hello,

I have a problem about using beforeFilter hook.
I want to cancel the filter process by some if condition, e.g. if user has unsaved data, and they change filter option, do not let user to set any filter and do not change the data on the view.

Currently what I did is in the hook ‘beforeFilter’ return false. But I see that it is only the view which not changed, but the filter is actually applied, and the filter arrow becomes green. Can you provide any suggestion on a way to how to not apply filter at all?

Best,
Terry

any workaround to it?

Hi @marius.editoiu

thank you for sharing this subject.

It is said that

Returns: {Boolean} If hook returns false value then filtering won’t be applied on the UI side (server-side filtering).

src https://handsontable.com/docs/7.2.2/Hooks.html#event:beforeFilter

But it doesn’t seem to be true here https://jsfiddle.net/6d45sq9o/ where the filter is applied for each column.
However, it works like this https://jsfiddle.net/6d45sq9o/1/

Nevetheless, you are right. I do not see why the dropdown menu arrow changed the color as the filtering is blocked. We also see that the option removed from the filter by value are still gone even if they are stll visible.

I reported this case here https://github.com/handsontable/handsontable/issues/6558 and will keep you updated with the changes.

Hello again @aleksandra_budnik ,

Thank you for your response. I see that the first jsfiddle example that you shared has a missing ‘n’ in line 26 in word ‘column’. But yes, it is a problem that in beforeFilter hook return false not behave correctly in the view. Currently I have a workaround to it, but I would like to change it after the issue is resolved.
For people who experiencing the same issue, my workaround to this is use filters plugin manually change the filter back inside the beforeFIlter hook before returning false.

let prevFormulaStack = []; // keep record of previous filter criteria
let filterInfinitePreventor = false;

hot.addHook(‘beforeFilter’, conditionsStack => {
if (filterInfinitePreventor ) {
filterInfinitePreventor = !filterInfinitePreventor ;
return false;
}
if (case_of_blocking_filter) {
filterInfinitePreventor = true;
const fP = hot.getPlugin(‘filters’);
fP.clearConditions();
prevFormulaStack.forEach((o) => {
o.conditions.forEach(© => {
fP.addCondition(o.column, c.name, c.args, o.operation);
});
});
fP.filter();
return false;
} else {
//case of not blocking filter
prevFormulaStack = conditionsStack; //keep record
return true;
}
});

1 Like