Add custom condition in filter plugin

Tags: #<Tag:0x00007efc62028798> #<Tag:0x00007efc62028658>

I’d like to add a custom condition in the filter plugin, how can I do that?

Our use case is that we implement our own dropdown menu for filters (like in handsontable, but with our custom UI) we have “Filter by condition” (two items) and logical operator (and/or) like in handsontable dropdown menu. currently, we can trigger filter by control filtering programmatically as suggested in this blog

We have no problem so far, but we’d like to add our own custom condition other than the list here
https://handsontable.com/docs/javascript-data-grid/api/filters/#addcondition (e.g., only cell is valid)

We tried to search and found that we can use hide plugins as suggested here

but we don’t want to do that way because we need to implement “and/or”(conjunction/disjunction) with ourself, and filter by the condition is also applied related to “filter by value”. Also, filters can be applied to multiple columns. It’s quite hard(and takes a lot of effort) to keep these states and logic by ourselves.

The best solution we can think of is we would like to add our own custom condition, so that “and/or”(conjunction/disjunction) handle automatically.

We digged into Handsontable and found that Handsontable also registers builtin filter condtion

So how do we register our own custom filter condition?

Hi @elecwebmaker

The solution provided by my colleague is the one we would recommend to modify the conditions without heavy modifications. The other option would be to write your own filter plugin that would consists of all the necessary implementations you need.

Thank you. Can we adjust existing filter plugin provided by handsontable by register new condition?

Hi @elecwebmaker

As I mentioned previously, you would need to build your own version of the plugin.

@adrian.szymanski Could I create a feature request (I’m not sure it already exists)? because I think it would open more possibilities to do many things. I think we should provide user to custom it because creating a new plugin because of only adjust existing condition (For example, implementing “is equal to” to be case sensitive, etc.) or adding a new one (For example, only valid cell, only row that has x characters, etc.) takes too much effort and it’d be impossible for handsontable to provide all of custom and it shouldn’t.

Implementing by hide rows can works for basic cases. It’s different with filter.

  1. visual row index in filter after filtered is consecutive but hide row is not.
  2. hide row doesn’t support “filter by value” and "and/or(conjunction/disjunction). which means we need to reimplement it even though filter already support this.

For sorting, handsontable provide user to custom sorting functionality, which it’s really awesome and I just need to write my custom logic without interfering of ui state of the table at all.

in the handsontable code, the structure of custom conditions is quite suitable and structured well for implementing custom conditions. The problem is there’s no public API.

However, I can find the solution to be able to add my custom condition already and it works well by overriding the “addCondition” of handsontable. the only problem is the override function need to be updated if the function is updated in handsontable codebase in the future. The only reason that I need to override the function is handsontable doesn’t expose the API for add custom, but the sturucture is already well supported.

@elecwebmaker

We appreciate your input and ideas. You can freely create a feature request here: https://github.com/handsontable/handsontable/discussions

Then we can discuss it with the development team.

1 Like

I will close this issue so we can continue at the GitHub discussions panel.