I'm using the DataTables library, with hierarchical data. What I wish to do is to have the groups always appear in the same order, and have the column sorts apply only within groups.
For example, with the following table:
GROUP FOOD
===================
fruit banana
fruit pear
fruit apple
meat steak
meat chicken
meat pork
vegetable zucchini
vegetable broccoli
vegetable tomato
When the user clicks the "food" column, it should sort ascending as follows:
GROUP FOOD ▲
===================
fruit apple
fruit banana
fruit pear
meat chicken
meat pork
meat steak
vegetable broccoli
vegetable tomato
vegetable zucchini
When the user clicks the "food" column again, it should sort descending as follows:
GROUP FOOD ▼
===================
fruit pear
fruit banana
fruit apple
meat steak
meat pork
meat chicken
vegetable zucchini
vegetable tomato
vegetable broccoli
However, the actual behavior is that it also inverts the ordering of the groups:
GROUP FOOD ▼
===================
vegetable zucchini
vegetable tomato
vegetable broccoli
meat steak
meat pork
meat chicken
fruit pear
fruit banana
fruit apple
This example shows how to write a custom sort function; however, there's no way of knowing from within the function if the column is being sorted ASC or DESC. What is the best way to specify a different sort function for ASC vs. DESC order on a given column?