disable sorting on specific row using css class

disable sorting on specific row using css class

oplanoplan Posts: 2Questions: 0Answers: 0
edited March 2010 in General
hi,
i'm very impressed by your datatables very nice work man :)
i have only one problem in my implementation: i have a grid with column that i don't want to be sortable (there are buttons so it's pretty useless to sort it). But the only solution i've found is to write down an array describing col by col whether to be sortable or not. My situation is more complex - i have several views including with different count of cols in the table, so i'm not able to write it to an array. Is there some possiblity to set that column with class="buttons" won't be sortable?
Thanks a lot :)

Replies

  • allanallan Posts: 63,522Questions: 1Answers: 10,473 Site admin
    Hi oplan,

    Thanks for the kind words. I think you've hit upon the biggest annoyance / limitation with DataTables at the moment - the need to specify every column in the aoColumns array. I plan to ease this in v1.7 (when that happens), although not 100% what the best way is to do it yet), but intil then what you could perhaps do, is to dynamically construct aoColumns based on information in the DOM. So a little loop over the column headers looking for a class and contructing an array would do the trick nicely I think.

    Regards,
    allan
  • oplanoplan Posts: 2Questions: 0Answers: 0
    Hi allan,
    thanks for quick reply
    i'll try to solve it as you described
    lookin forward 1.7 version :)
    i'll check your project from now often!
    bless :)
  • AlexanderAlexander Posts: 17Questions: 0Answers: 0
    Hi Allan,

    Answer please.
    Have you decided the issue?

    Thanks
  • AlexanderAlexander Posts: 17Questions: 0Answers: 0
    The thing is:
    the last row of the table is the sum of the columns. When sorting, this line should not move.
    Answer please, can I make it the standard tools? Or, for example, sort, and then fnDrawCallback moved to the bottom of the table this row.
    Similar questions on the forum was a lot, I think the answer will be helpful to many.
  • AlexanderAlexander Posts: 17Questions: 0Answers: 0
    Can any body help me?
  • allanallan Posts: 63,522Questions: 1Answers: 10,473 Site admin
    The original question was about disabling sorting with a targeted class - that was added to DataTables 1.7 by using aoColumnDefs.

    Your question sounds quite different:

    > the last row of the table is the sum of the columns. When sorting, this line should not move.

    So a footer then? Something like this: http://datatables.net/examples/advanced_init/footer_callback.html

    Allan
  • AlexanderAlexander Posts: 17Questions: 0Answers: 0
    Thank you for your help.
  • AlexanderAlexander Posts: 17Questions: 0Answers: 0
    Not quite, aoColumnDefs acts on the column, not row, and it is necessary that only one row or several rows in the column is not sorted, and the column sorted as usual.
    footer callback not suitable.
  • AlexanderAlexander Posts: 17Questions: 0Answers: 0
    may be possible to take an array of sorted data before showing in the table, change it and show in the required form?
  • allanallan Posts: 63,522Questions: 1Answers: 10,473 Site admin
    All rows in the TBODY element are sorted - it is not currently possible to exclude any of the rows in TBODY from the sorting (it is possible to write a custom sorting plug-in to force the sorting if you wanted, but I'm don't see how that would work with pagination).

    If you want a row to always be visible, regardless of the sorting, it either needs to be in the header or footer - or dynamically injected on each draw.

    Allan
  • johnnyg24johnnyg24 Posts: 1Questions: 0Answers: 0
    edited April 2011
    allan,

    I am running into the same problem as Alexander. I need the last row of my table to not sort because is hold the table's Totals. Of coarse this should be placed in a tfoot row however, when a user prints the table the footer repeats on every page. I don't like this because it looks like the totals on each page pertain to that specific page when in reality it is the total of all the pages. It leads to confusion for the users. The only quick work around I see is to have a separate table that holds just the totals right under the table being sorted. This way it looks like a footer row, will remain in place when paging and will print only once on the last page.

    To keep the columns formatted with the same widths:

    [code]
    $("#masterTable th").each(function(i){
    $("#footerTable td").eq(i).css('width', $(this).width())
    })
    [/code]
  • AlexanderAlexander Posts: 17Questions: 0Answers: 0
    thanks johnnyg24,
    perfect solution and it looks good
This discussion has been closed.