Can I set the default state of a column filter?

Tags: #<Tag:0x00007f8b2b0a4f20>

Hello,

I am trying to change the default state of the filter for one of my columns. This column is a dropdown column which can have several options. What I want to do is to not color the button for the dropdown if the filters have the default state, and color it if the filter state is different than the default one.

For instance, let’s assume that I can have the following values for the dropdown from my column {A, B, C, D, E}. My default state is that A, B and C are selected while D and E are not. Whenever the filter state is different I want to have the filter button colored.

What I have done was to manually add/remove the “htFiltersActive” style class in the “afterGetColHeader” hook. This works perfect for most of the times. However when in the table I do not have data for the {D, E} values, and I change on one of my rows the value to D or E, the afterGetColHeader is not called so the “htFiltersActive” style class is not applied.

How can I solve this issue? Can I set a default value for my filter that creates this functionality, or perhaps a way to trigger the afterGetColHeader hooks?

Thank you in advance for your help!
Marius Comiati

1 Like

Hi @marius.comiati

We haven’t prepared API for Filters for changing the state of the button. Every idea should be treated as customization that is not officially supported.

The afterGetColHeader should be the correct hook to use. Can you attach a demo with your current implementation? f that is confidential please send it to support@handsontable.com

I will have to check if I can send the code via email since it is as you said, confidential. I tried using the afterGetColHeader hook and it work as expected. There is however, a corner case that I wasn’t able to fix, since the hook is not triggered in this case. This is when for instance, the possible values for my column is {A, B, C, D, E} but in the table I only have data with {A, B}. In this case, if I change on one of my row the value to either D or E, the hook is not called. I also tried calling it manually but I do not know how can I create the HTMLTableHeaderCellElement parameter that the hook needs.

Hi @marius.comiati

do we have any updated on the subject?