Disable sorting when clicking on headers

Disable sorting when clicking on headers

bzakharinbzakharin Posts: 2Questions: 0Answers: 0
edited December 2010 in General
Can I disable sorting when clicking on the header of a column without disable sorting on that column? What I mean is, I want to still be able to sort using that column manually using something like

oTable.fnSort([[2,'asc']]);

Thanks in advance,
Boris Zakharin

Replies

  • bill.martinobill.martino Posts: 38Questions: 0Answers: 0
    Did you ever figure this out? I am trying to do the exact same thing.
  • bzakharinbzakharin Posts: 2Questions: 0Answers: 0
    No, I worked around this by disabling sorting on that column and sorting on a hidden column instead.
  • allanallan Posts: 61,743Questions: 1Answers: 10,111 Site admin
    You could unbind the click event on the TH element - that would do the trick nicely.

    Allan
  • bill.martinobill.martino Posts: 38Questions: 0Answers: 0
    AH! of course:

    $('TH').unbind('click.sorting');

    seems to be working for my purposes so far.
  • thirdythirdy Posts: 2Questions: 0Answers: 0
    Hi, I have the same situation but I need to bind the sorting event to the table header text. This is bec I have other elements in my TH. Any help for this?
  • allanallan Posts: 61,743Questions: 1Answers: 10,111 Site admin
    Did you try unbinding and then adding the sort listener using fnSortListener to the element you want?

    Allan
  • ccecce Posts: 1Questions: 0Answers: 0
    it looks like you have to do $('th').unbind('click.DT') now, judging from the latest releases of DT..
  • elgarchelgarch Posts: 13Questions: 0Answers: 0
    edited April 2012
    Hello Everybody,

    I'm looking for the same functionnality, i tried $('TH').unbind('click.sorting'); it did't work for me.
    @cce i tried $('th').unbind('click.DT') and it works perfectly thanks :)

    now what i'm looking for is how to re-bind again the click, is there any way to that, i thought $('th').bind('click.DT') could work but it doesn't.

    any suggestion would be appreciated
    Thanks
  • allanallan Posts: 61,743Questions: 1Answers: 10,111 Site admin
    Have a look at fnSortListener - that is the function that DataTables uses to attach sort listeners.

    Allan
  • elgarchelgarch Posts: 13Questions: 0Answers: 0
    Thanks Allan for the quick answer, yupe the method does the job, this is what i did

    oTable.fnSortListener( $('thead.theadergray th'),0);

    this sort always by the first item th, event if when we click on another th. the sort is always done on the first th, what i want is to sort by the clicked th, is there any way to tell the plugin to sort by all those th nodes, like that for example :


    oTable.fnSortListener( $('thead.theadergray th'),0,1,2,3,4,5);

    Thanks a lot Again Allan
  • elgarchelgarch Posts: 13Questions: 0Answers: 0
    I tried this solution, it's works for now, hope it will help someone :)

    for(var i=0; i< oTable.fnSettings().aoColumns.length; i++){
    oTable.fnSortListener($('thead.theadergray th:eq('+i+')'), i);
    }

    Thanks guys for the great work ;)
This discussion has been closed.