Combine asSorting with iDataSort
Combine asSorting with iDataSort
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.
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.
This discussion has been closed.
Replies
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
> 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
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