Disable table header click

Disable table header click

Rawland_HustleRawland_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

  • allanallan Posts: 63,237Questions: 1Answers: 10,418 Site admin

    Is there a way of disabling the sorting when a table header is clicked?

    You could remove the click event listener that DataTables add:

    $('#example thead th').off('click');
    

    http://live.datatables.net/rekoyowe/1/edit

    Allan

  • Rawland_HustleRawland_Hustle Posts: 94Questions: 16Answers: 0

    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?

  • allanallan Posts: 63,237Questions: 1Answers: 10,418 Site admin

    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().

    Also, how do I remove the pointer that shows when you hover the table headers?

    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

  • Rawland_HustleRawland_Hustle Posts: 94Questions: 16Answers: 0

    @allan Thank you!

  • Rawland_HustleRawland_Hustle Posts: 94Questions: 16Answers: 0

    @allan I'm not sure I understand. What should be inside the element that I attach the listener to?

  • Rawland_HustleRawland_Hustle Posts: 94Questions: 16Answers: 0

    @allan Do you mean I should wrap the arrows somehow?

  • allanallan Posts: 63,237Questions: 1Answers: 10,418 Site admin

    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

  • Rawland_HustleRawland_Hustle Posts: 94Questions: 16Answers: 0

    @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?

  • allanallan Posts: 63,237Questions: 1Answers: 10,418 Site admin

    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

  • Rawland_HustleRawland_Hustle Posts: 94Questions: 16Answers: 0

    @allan Thank you for your response!

Sign In or Register to comment.