Mark external sorted column without sorting again

Mark external sorted column without sorting again

dragon013dragon013 Posts: 8Questions: 3Answers: 0
edited October 2014 in Free community support

Hello,

I disabled the initial sorting because I have to use sorted data getting straight from the database. Though the user should be able to do some sorting after the initial start - this part is working. The nice is that the sorting column is marked then.

Now I do have the task to mark the column on which the initail sorting took place without doing any sorting within datatables. For example: the database gives me a list sorted by title, I do show this sorted list with datatables and now I want to mark the column "Title" without doing any other sorting. Kind of changing the style for a special column.

Is there any way to get this done ?

Thanks in advance!
dragon.

This question has an accepted answers - jump to answer

Answers

  • john_ljohn_l Posts: 45Questions: 0Answers: 12

    I can think of two options:
    1) Just set up an initial sort that is identical to how the data is sorted from the server - then the headers will have the correct classes to show the sort indicators.
    2) Manually add the classes needed to the headers after the table has been initialized.

  • dragon013dragon013 Posts: 8Questions: 3Answers: 0

    Thanks for the answer. I already tried option 1 before. It works, but: the order coming from the database is different to the order which datatables provides, so sadly I can not use this option because the initial sorting is done regardless of the external sorting.

    Option 2 is the best way (in my view), but I still did not figured out how to add the class to the cells / the column. But I will keep trying.

  • john_ljohn_l Posts: 45Questions: 0Answers: 12
    Answer ✓

    You should be able to do it with something like this:

    $('#example > thead > tr > th:nth-child(1)').removeClass('sorting').addClass('sorting_asc');
    $('#example > tbody > tr > td:nth-child(1)').addClass('sorting_1');

  • dragon013dragon013 Posts: 8Questions: 3Answers: 0

    Works like a charm! Thanks!

This discussion has been closed.