Sorting by a column, then freezing some rows, then sorting by a different column.
Sorting by a column, then freezing some rows, then sorting by a different column.
Here is the situation. I have two columns that need to be sorted, one is fruit and the second is date.
What I am looking to do is sort by the first column so that specific fruit is at the top and "freezing" those rows. Then a sort on the Date column would sort the frozen rows, keep them at the top and sort the rest of the rows by date.
Example: apple to be first
apple, 1980/8/1
orange, 1980/2/1
pear, 1980/5/1
orange, 1980/4/1
apple, 1980/1/1
pear, 1980/3/1
So:
apple, 1980/1/1
apple, 1980/8/1
orange, 1980/2/1
pear, 1980/3/1
orange, 1980/4/1
pear, 1980/5/1
Apple would always be first then sorted by date. The rest would just be sorted by date.
I did figure out a solution the ended up pulling "apple" out, sorting it and putting it back at the top but it was far from elegant. This did not allow for sorting via the asc/desc buttons.
Answers
I would consider using
columns.render
for this to affect sorting. Haven't tested it but I think something like this would work:You would replace
'apple'
with the variable containing the fruit you want at the top. Of course you will need to setup your column ordering properly to have the date column follow the fruit column.Kevin
Had time to check this out and found my initial answer is not quite correct. I created an example that seems to work:
http://live.datatables.net/sowidusi/1/edit
It uses
columns.render
but differently. If the row has "apple" or whatever is selected it subtracts 1000 years from the date just for the sorting process. It leaves the date alone for the other processes. This subtraction of 1000 years may or may not work for you but hopefully will get you headed in the right direction. Here is the updatedcolumns.render
:Kevin
Sorry for the delay in replying, end of a sprint so didn't have time to check back. Will have to check this out now that I have a little time. Thanks.