Record order changes by performing sort on multiple columns consecutively.

Record order changes by performing sort on multiple columns consecutively.

dre.ankurdre.ankur Posts: 2Questions: 1Answers: 0

On this example http://live.datatables.net/

  1. Sort on name in descending order and then on office in descending order : 1st record is Zorita Serrano
  2. Sort on salary in descending order and then on office in descending order : 1st record is Gavin Cortez and 2nd is Zorita Serrano.

I have a use case when I want to have Zorita Serrano as 1st record when I sort on office column, no matter how many sorts I do previously.

What the option/implementation to have consistent grouping / ordering of records?

Thanks
Ankur Dohare

Answers

  • kthorngrenkthorngren Posts: 21,167Questions: 26Answers: 4,921

    Are you saying that you always want the name column sorted descending? If so then orderFixed is what you want to use. Or possibly the solution presented in this blog.

    Kevin

  • dre.ankurdre.ankur Posts: 2Questions: 1Answers: 0

    Applying order fixed has not worked for this usecase. Is there any way I can clear order before sort is applied and the draw.

    I get into an infinite loop if I capture order event and apply draw inside it. Obviously. But clearing order before draw will solve the usecase.

  • kthorngrenkthorngren Posts: 21,167Questions: 26Answers: 4,921

    capture order event and apply draw inside it.

    That will cause a loop since draw() updates the table order causing the order to fire.

    I'm not clear on what you want to do. There is not a built-in way to force Zorita Serrano in the Name column to the top when sorting by other columns. Maybe you can use a hidden column that as the value of 1 for the row with Zorita Serrano and 0 for the remaining rows. Then using orderFixed you can always sort by that hidden column.

    Kevin

This discussion has been closed.