Skip to content
Wobin edited this page Jun 16, 2014 · 2 revisions

Include the LibSort folder in your addon and include the file in your toc

<Script Name="Libs\LibSort-1.0\LibSort.lua"/>

Create a reference in your addon lua

local LibSort = Apollo.GetPackage("Wob:LibSort-1.0").tPackage

Create a sort function

function MyAddon:SortLevel(a, b)	
    local la, lb = a:GetRequiredLevel(), b:GetRequiredLevel()
    if la == lb then return 0 end
    if la < lb then return -1 end
    return 1
end

And then register your sort function

LibSort:Register("MyAddon", "Level", "Sort by Level", "Level", 
                     function(...) return MyAddon:SortLevel(...) end)

Now you can apply the sort into whichever bagWindow you have prepared

For this example, we'll hook into the default Carbine inventory

local Inventory = Apollo.GetAddon("Inventory") 
local bag = Inventory.wndMainBagWindow
bag:SetSort(true)
bag:SetItemSortComparer(function(...) return LibSort:Comparer("MyAddon", ...) end)	
Clone this wiki locally