Best way to prevent column sorting when icon is clicked
Best way to prevent column sorting when icon is clicked
I have icons next to my column headers. All columns are sortable. Clicking the icon next to the header sends off an ajax request that gets descriptive information about the column and displays it as a bootstrap popover. The problem is that clicking the icon additionally sorts the table, which is not the desired behavior. I want to prevent sorting of the table on the icon click. Is there a way to intercept the click event on an icon in the header and prevent the sort. The best I've come up with is using fnPreDrawCallback to get the last sort and to set it to the new sort.
Answers
If these are icons that you added yourself in the header, you need to event.stopPropagation() on your click event.
https://api.jquery.com/event.stoppropagation/
You would put that in either the bind or the inline onclick event. When you normally click on something, it propagates all the way up the nodes until something tells it to stop.