Originally Posted by Aeriez
Is FauxScrollFrame capable of, say, a 3-4 column sheet (ie: Listing players, their class, their dkp etc) that is sortable by each column?
|
Absolutely it is. The auction house uses a ScrollFrame based on FauxScrollFrameTemplate to implement the browse portion, which can also be sorted by the column tabs at top.
Here is the template blizz uses for the AH sort tabs,
here is an example of how that template is used in xml, and
here is the sorting being done in lua.
For your case you would need to store some state like the direction of the sort, but that would be pretty simple. You could use table.sort to reorder the source of the FSF, with the sort func being tied to the column and direction. After that you just run your Update function to repopulate the FSF with the newly ordered data.
Lua Code:
local data = {
{player="Sveng",class="Mage",dkp=1.41},
{player="Sarex",class="Rogue",dkp=-50}
};
function MyFrame_Update()
local offset = FauxScrollFrame_GetOffset(MyScrollFrame);
for i=1,MAX_ROWS do
local row = _G["MyScrollFrameRow"..i];
local rowData = data[i+offset];
if (rowData ~= nil) then
-- set row data
row:Show();
else
row:Hide();
end
end
FauxScrollFrame_Update(MyScrollFrame, #data, MAX_ROWS, ROW_HEIGHT);
end
...
-- 'true' being asc, 'false' being desc, 'nil' being unsorted
local sortDirections = {player=nil,class=nil,dkp=nil};
local function sortData(propKey, direction)
sortDirections[propKey] = direction == "asc"
table.sort(data, function(a,b)
if (a[propKey] == b[propKey]) then
return nil;
end
if (sortDirections[propKey]) then
return a[propKey] < b[propKey];
else
return a[propKey] > b[propKey];
end
end);
FauxScrollFrame_SetOffset(MyScrollFrame, 0);
MyFrame_Update();
end
sortData("dkp", "desc");