Multi-Column Sort where one column follows another.

Multi-Column Sort where one column follows another.

wiredwired Posts: 4Questions: 0Answers: 0
edited August 2010 in General
This is my first post to this forum - I'm pretty new to Javascript, HTML, and CSS, so DataTables has been a godsend to me. This is an amazing tool and I couldn't possibly convey to Allan how much it has helped me for my application.

My question is this - I would like to do a multi-column sort where Column 2 follows Column 1 (for which I have written a custom sType sorting function). This is to say, if the user clicks on Column 1 and sets it to ascending, I would like the secondary sort to be Column 2 ascending. If this user sets Column 1 to descending, I would like Column 2 to also be descending. I see there is a way to have the desired sort set up when the table is initialized, but how can I change the secondary sort to match the primary? I'm sure there's an easy way and a hard way, and given my inexperience I'd probably come up with the hard way ;)

BTW, as a suggestion for future enhancements, it would be really cool to be able to initialize the sorting parameter as follows: "aaSorting": [[ 1, "desc" ],[ 2, "coln" ],]

In my case, 'n' would be 1, but in general the "coln" would indicate that the column is sorted however column 'n' is specified (could also just be "1" instead of "col1"). This could indicate that the initial sort is column 1 descending, followed by column2 sorting in the direction of column 1. Then, when the user clicked on column 1 to switch to ascending, column 2's sort would also be ascending.

This might be a pretty simple modification (I'm guessing here) that would provide even more versatility to an already incredibly versatile tool.

Anyway, back to my question - is there an easy way to set up what I would like to do?

Replies

  • wiredwired Posts: 4Questions: 0Answers: 0
    Wow - I must not have had enough coffee - I'm looking at my table now, and it's doing exactly what I want it to do. I could have sworn that yesterday it wasn't. Apparently what I just described as an enhancement is the default mode of operation. Way to go Allan - you solved my problem already!
This discussion has been closed.