sort two columns depending on the most recent data entered

sort two columns depending on the most recent data entered

jdiaz11jdiaz11 Posts: 6Questions: 5Answers: 0

I have a problem I have a table that I want to sort by date so that the most recent data is first and another column that is numeric that I also want to sort so that the fields that are empty go below those that are not and if I did it with "order" but when I do that it breaks the descending order of the date is there a way to sort without breaking the order of dates.
thank you for your help

Link:https://stackoverflow.com/questions/73627434/sort-two-columns-depending-on-the-most-recent-data-entered

Answers

  • kthorngrenkthorngren Posts: 20,139Questions: 26Answers: 4,734
    edited September 2022

    There are probably multiple ways to accomplish this. I chose the easy way but it might not be the most efficient. I think I understand what you are looking for. I took your code from the SO thread to create a test case.
    http://live.datatables.net/didefipu/1/edit

    I updated Garrett Winters to have $ 13.00 instead of blank just for demo purposes. It uses orthogonal data to set the sort value for the numeric column based on the sort direction, for example, 0 for desc or 9999999 (some large number) for asc.

    The order event is used to invalidate the data in column 3 (causing columns.render to run for column 3) if that column is being sorted. If you comment this out you will see that sorting works the first time its changed but not after. You could keep track of the previous direction to only invalidate the cells if the direction changes.

    I set orderFixed for column 2 just to make the demo easier so you don't have to keep that column sorted. You can remove it if you wish.

    Is this what you are looking for?

    Someone may post a better solution.

    Kevin

Sign In or Register to comment.