Hi @kmd2
There’s a callback that detects a click on a column cell/header, you can use that. It is called afterOnCellMouseDown
(ref: https://handsontable.com/docs/javascript-data-grid/api/hooks/#afteroncellmousedown).
Based on the available callback parameters we can base our condition to fire custom logic only when a column header is clicked. Then to check what index of a header that is
afterOnCellMouseDown: function(e, coords, TD){
if(coords.row < 0){
console.log(`header ${coords.col} clicked`)
}
}
Demo: https://jsfiddle.net/csb4uq1p/
Then, as a second step we will add the filters logic (here you have to remember to add the filters: true
to the configuration to enable the filter).
filters: true, //enabling filters
and filters logic
afterOnCellMouseDown: function(e, coords, TD){
if(coords.row < 0){
let filtersPlugin = this.getPlugin('Filters');
let filtersApplied = filtersPlugin.conditionCollection.filteringStates.orderOfIndexes; //array of column indexes with conditions applied
if(coords.row && !filtersApplied.includes(coords.col)){
filtersPlugin.addCondition(coords.col, 'not_empty', []);
filtersPlugin.filter();
} else {
//remove filters
filtersPlugin.clearConditions();
filtersPlugin.filter();
}
}
}
Demo: https://jsfiddle.net/csb4uq1p/3/