Disable sorting for column 'special' columns

Disable sorting for column 'special' columns

dzidadzida Posts: 23Questions: 0Answers: 0
edited March 2010 in General
Hi guys,

I have following use case:

In most of my DataTables I have 'special' column called "Actions' and simply I don't want this column sortable.
Do you have idea how to disable sorting for all columns with let's say class="do-not-sort-me"?

Of course I know about bSortable feature but this leads to write special datatables initializator for each datatable I have, which is something I would like to avoid:)

Kind Regards,
Lukasz

Replies

  • allanallan Posts: 63,535Questions: 1Answers: 10,475 Site admin
    Hi Lukasz,

    This isn't directly possible in DataTables 1.6, although it might be included in 1.7 - depending on which way my implementation goes... Having said that, it certainly is possible to do something like this in 1.6, it just requires a few more lines of code. So what you need to do is loop over the columns in your table (probably the first thead>tr would do) and construct an array for aoColumns based on what is found in the table classes. It should be fairly straight forward if it's just the sorting you are interest it.

    The other option is that you could have the server-side construct the aoColumns array (I presume it would be it which is adding the class in the first place, so it knows what is what).

    A plug-in for building a DataTables initialiser out of HTML attributes is something I'd really like to do - it's been on the cards for a while. but one of those things that just hasn't been got around to... :-)

    Regards,
    Allan
  • abbottmwabbottmw Posts: 29Questions: 0Answers: 0
    Allan,

    I would really like this feature as Im using something exactly like this. I was using the tablesorter and the metadata plugin to specify the columns i dont want sorted. Made it easy because i didnt care where they were in the table.

    Thanks for all your hard work on this plugin!

    -Matthew
  • neuewerbungneuewerbung Posts: 3Questions: 0Answers: 0
    It's possible, try this:
    Add this to your Plugin:
    [code]
    jQuery.fn.dataTableExt.oSort['html-undefined'] = function(a,b) {
    return false;
    };
    $('.sorting_disabled').unbind('click');
    [/code]
    Settings for Tables:
    [code]
    aoColumns : null, null, null ...
    [/code]

    for Disabled Colums take this :
    [code]
    { "asSorting": [ ] }
    [/code]
  • allanallan Posts: 63,535Questions: 1Answers: 10,475 Site admin
    Nice trick that - like it :-)

    It's also possible to do using aoColumnDefs in 1.7 - target a specific column by the TH class name: http://datatables.net/usage/columns .

    Allan
  • ripperripper Posts: 1Questions: 0Answers: 0
    neuewerbung, nice workaround! works great.
  • srimanta12srimanta12 Posts: 12Questions: 0Answers: 0
    thanks a lot. It helps to solve my issue also.
  • dvnandoverdvnandover Posts: 42Questions: 0Answers: 0
    Where would the codes go into the jquery.datatable.js?
  • dvnandoverdvnandover Posts: 42Questions: 0Answers: 0
    edited September 2012
    Anyone?
This discussion has been closed.