Hi,
I’m trying to sort a table alphabetically on 2 values, but so far no luck.
The table should be sorted on category and within a certain category range the name field should also be sorted.
So all category “bread” should be on top and within this category all name values should also be sorted alphabetically.
local food = {
{category = “Bread”, name = “white”},
{category = “drinks”, name = “cola”},
{category = “Bread”, name = “corn”},
{category = “Bread”, name = “french”},
{category = “drinks”, name = “milk”},
{category = “drinks”, name = “soda”}
}
via :
local function tableSortCat (a,b) return a.category \< b.category end table.sort( foodlist, tableSortCat)
I’m able to sort on category only but not both.
Can anyone help me to solve this?
Thanks!