Disable table header click
Disable table header click
Rawland_Hustle
Posts: 94Questions: 16Answers: 0
Link to test case: https://themeadow.se/ntjperrors/
Debugger code (debug.datatables.net):
Error messages shown: No error code shown.
Description of problem:
Is there a way of disabling the sorting when a table header is clicked? I'd like it not to be treated as a link at all, but I do want the little up and down arrows to still work.
Replies
You could remove the click event listener that DataTables add:
http://live.datatables.net/rekoyowe/1/edit
Allan
Thanks, but that also disables the sorring arrows for me. I want them to work.
Also, how do I remove the pointer that shows when you hover the table headers?
Oh! You want to be able to click on the icons, but not the rest of the header? You would need to create an element inside the header that you can attach the ordering listener to -
order.listener()
.That's
cursor: pointer
in CSS - used to show that the cell is clickable. You'd need a little custom CSS to override that if you are going to remove that ability.Allan
@allan Thank you!
@allan I'm not sure I understand. What should be inside the element that I attach the listener to?
@allan Do you mean I should wrap the arrows somehow?
Correct - what you are looking for isn't available built into DataTables, so it would require some custom code. You'd need to add an element to the header cells and then apply the sort listener to that.
Allan
@allan Okay! But the arrows are already there and they are the ones I want to have the listener on. Should I remove them and put them in a new element?
The problem is that the arrows that are there are just a background image. You can't add an event listener to them. You could leave them there and put a floating element on top of them which you apply the event listener to.
Allan
@allan Thank you for your response!