Add custom button to header and catch click event

Tags: #<Tag:0x00007fbe9305ef48>

Hey guys, I was hoping you can help me here. I need to replace basic fillter (dropdown menu) that you have with custom button in column header that will open another window on click, so I need to catch click event when button is clicked. Here’s demo that you can use, will appreciate your help.

Hi @alext

You can use the afterOnCellMouseDown hook and where would be your icon.

But if I will use it my sorting will be disabled right? Is there a way to keep sorting functionality and catch click event? Basically I need to click on my custom button and it should do one thing and by clicking on cloud icon it should do sorting.
Please let me know if it can be done, thank you.

Column sorting works only for text, example


If you would like to use icons only and provide sorting for columns you can use the same hook - afterOnCellMouseDown to trigger sorting.

afterOnCellMouseDown: function(e, coords, TD){
      	this.getPlugin('columnSorting').sort({ column: coords.col, sortOrder: 'asc' });

you’d just need to check the sorting order to change asc to desc.

Thank you and to clarify I can catch click event only from Cell, but not from added to header custom button, right?

if you click a button inside the cell/header you will also trigger the afterOnCellMouseDown.

ps. if you’d ever what to do something before the default behavior or stop the default behavior you can use the beforeOnCellMouseDown src: