Quantcast
WoWInterface - View Single Post - Order by name
Thread: Order by name
View Single Post
09-13-14, 02:43 PM   #3
Tageshi
A Murloc Raider
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 7
Another example, where I assumed you want to sort Accountant_Data with its tiltles.

Lua Code:
  1. Accountant_Data = {
  2.    ["TRAIN"] = {title = "ACCLOC_TRAIN", somedata = "foo"},
  3.    ["TAXI"] =  {title = "ACCLOC_TAXI", somedata = "bar"},
  4.    ["TRADE"] = {title = "ACCLOC_TRADE", somedata = "something"},
  5.    ["AH"] =    {title = "ACCLOC_AUC", somedata = "something"}
  6. };
  7.  
  8. local sorted_keys = {};
  9. local idx = 0;
  10. for k,v in pairs(Accountant_Data) do
  11.    idx = idx + 1;
  12.    sorted_keys[idx] = k;
  13. end
  14.  
  15. table.sort(sorted_keys, function (fst, snd)
  16.       return Accountant_Data[fst].title < Accountant_Data[snd].title;
  17. end);
  18.  
  19. for idx = 1, #sorted_keys do
  20.    local key = sorted_keys[idx];
  21.    print(Accountant_Data[key].title);
  22. end

Last edited by Tageshi : 09-13-14 at 02:46 PM.
  Reply With Quote