Combine asSorting with iDataSort

Combine asSorting with iDataSort

gary46cargary46car Posts: 3Questions: 0Answers: 0
edited October 2013 in General
Hi,

I am new to datatable which is a fantastic tool.
I just face one issue that I want to have a third option in asSorting which is sorting by a hidden column.

For example:
For Column1, I used sType and asSorting ["asc", "desc"]. Everything works fine.
However, I would like to introduce a third sorting way in Column1 which is sorted by Column2 (a hidden column),
like asSorting["asc", "desc", "sortByColumn2"]. So the third time the user click the Column1 header, it can be sorted by Column2, which in my scenario is default.

I had tried to use iDataSort to sort by Column2 and it works fine. I am wondering is there a way to set the iDataSort as a third parameter in asSorting to achieve what I want to? Or is there other ways I can do?

Thanks in advance.

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    That's an interesting idea. I'm sorry to say it isn't possible with the native controls in DataTables at the moment, but it is something I will consider for the future. Until then, you'd need to attach your own click event handler to the table cell that you want to activate the sorting and then use the fnSort function to run the sort as you require.

    Allan
  • gary46cargary46car Posts: 3Questions: 0Answers: 0
    Hi, Allan,

    Currently, my alternative is to disable bSort, set sType for columns, and use fnSort to sort by creating a dropdown list as navigation. It works fine. What I want to know is am I doing the right thing?
    Also you mentioned that I can achieve this via creating my own click event handler. Could you please give me more details about how to do that and what functions in datatable I should use?

    Many thanks
    Gary
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Sounds perfectly reasonably to me.

    > Also you mentioned that I can achieve this via creating my own click event handler. Could you please give me more details about how to do that and what functions in datatable I should use?

    Sounds like you've done all the parts already. All I was suggesting was that you would have an element that you click on which will call fnSort . You could unbind the default click listener DataTables adds to the header cell if you want to replace it with your own.

    Allan
  • gary46cargary46car Posts: 3Questions: 0Answers: 0
    Thank you for your quick response.
    I think that would be all. And if it is possible, please consider to introduce this function into datatable, so user can have more sorting options.
    Thanks again Allan. Wish you all the best.

    Gary
This discussion has been closed.