Quantcast
Order by name - WoWInterface
 
Thread Tools Display Modes
09-13-14, 11:04 AM   #1
Tntdruid
Premium Member
 
Tntdruid's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Jan 2005
Posts: 55
Order by name

Can't find a way to order it by name.

See screen.


Link to the code https://github.com/Tntdruid/Accounta...Accountant.lua


Trying to update one of my fav old addons
Attached Thumbnails
Click image for larger version

Name:	WoWScrnShot_091314_185723.jpg
Views:	134
Size:	401.7 KB
ID:	8205  
  Reply With Quote
09-13-14, 01:46 PM   #2
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,537
I haven't tested this but it is a variant of one that was listed at : http://forums.coronalabs.com/topic/4...e-on-2-values/


Lua Code:
  1. -- Sort Function
  2. local function SortTableByKey(a, b )
  3.   if (a.key < b.key) then
  4.     return true
  5.   elseif (a.key > b.key) then
  6.     return false
  7.   end
  8. end
  9.  
  10. -- Build table that can be sorted
  11. local accountant_sorted_data = {}
  12. for key,value in pairs(Accountant_Data) do
  13.   table.insert(accountant_sorted_data = { "Key" = key, "Value" = value })
  14. end
  15.  
  16. -- Sort Table
  17. table.sort( accountant_sorted_data, SortTableByKey)
__________________
  Reply With Quote
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
09-14-14, 01:44 AM   #4
Tntdruid
Premium Member
 
Tntdruid's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Jan 2005
Posts: 55
Thanks , time to see if i can get it too work
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Order by name

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off