Quantcast

Added a table-index sorting utility function.

pschifferer [10-21-09 - 02:56]
Added a table-index sorting utility function.
Made the shopping list sort items under each toon alphabetically.
Filename
CauldronShoppingListUI.lua
CauldronUtil.lua
diff --git a/CauldronShoppingListUI.lua b/CauldronShoppingListUI.lua
index 97eb169..90ebead 100644
--- a/CauldronShoppingListUI.lua
+++ b/CauldronShoppingListUI.lua
@@ -109,7 +109,9 @@ function Cauldron:UpdateShoppingList()
 			frameAbove = shoppingListRequestor;

 			-- add items for the requestor
-			for item, amount in pairs(items) do
+			for item in pairs(Cauldron:SortTableIndices(items)) do
+--			for item, amount in pairs(items) do
+				local amount = items[item];

 				local shoppingListItem = _G["CauldronShoppingListItem"..itemIndex];

diff --git a/CauldronUtil.lua b/CauldronUtil.lua
index e43942f..656bfa9 100644
--- a/CauldronUtil.lua
+++ b/CauldronUtil.lua
@@ -230,3 +230,21 @@ function Cauldron:GetMerchantItems()

 	return items;
 end
+
+function Cauldron:SortTableIndices(t)
+
+	if not t then
+		return {};
+	end
+
+	local a = {};
+
+	for n in pairs(t) do
+		a[#a + 1] = n;
+	end
+
+	table.sort(a);
+
+	return a;
+end
+