PDA

View Full Version : windowlist - sortby and onSortCompare



Xarxus
February 10th, 2023, 21:51
I'm not sure I understand the windowlist sortby tag, or maybe I'm using it wrong. Using the sortby tag
I can define a control (or DB field) of the class to be used for sorting. But do I need to define the
onSortCompare function as well?

In the examples I see in the coreRPG it doesn't seem to me to be defined. The problem is that if I don't define
it, my list doesn't get sorted, if I define it instead I'm forced to choose which field I want to use for the sort in
the onSortCompare function, so I don't understand why I should also define the tag.

The following code comes from utilty_dice.xml (coreRPG). There doesn't appear to be any script here.
<windowlist name="list_skin">
<anchored to="frame_skin">
<top offset="35" />
<left offset="10" />
<right offset="-15" />
<bottom offset="-15" />
</anchored>
<class>diceselect_skin_group</class>
<readonly />
<sortby>
<control desc="true">owned</control>
<control>order</control>
</sortby>
</windowlist>

Trenloe
February 10th, 2023, 23:09
If you have a <sortyby> entry in the windowlist definition you don't need an onSortCompare function.

onSortCompare is to allow you to do more complex sorting.

Xarxus
February 11th, 2023, 10:58
That's my problem. If I do not define a onSortCompare function, but I use the sortby tag, the list doesn't sort.
The order remains the same as the DB. So if an alphabetically minor element is found after, it stays after.
The applySort function only works with onSortCompare, right?

Should I do something else to order the list using sortby?

Trenloe
February 11th, 2023, 10:59
Please provide the XML definition you're using that doesn't work. For the windowlist and for the windowclass used within the windowlist.

Xarxus
February 11th, 2023, 12:49
I've discovered something, let me show my code.
This are the fields in the class I use for the windowlist items. It's a generic class that I use for some windowlist.
controlbuttonitemlink is a buttoncontrol and controlformattedtextfield is a formattedtextfield.

NB If is use the sortby with formattedname, it doesn't work, but if I use first_control, everything goes well.


<hsx name="open" source="open" />
<hsx name="openclass" source="openclass"/>
<hsc name="first_control" />
<hsc name="hoverField" />

<controlbuttonitemlink name="button_item_link">
<anchored position="insidetopleft" offset="4,2" />
</controlbuttonitemlink>
<controlformattedtextfield name="formattedname">
<anchored position="insidetopleft" offset="29,4" />
<nohide />
<readonly />
<script file="common/scripts/controlbuttonitemlink.lua" />
</controlformattedtextfield>

This is my windowlist.
<windowlist name="my_list">
<allowdelete />
<anchored position="insidetopleft" >
<top offset="30" />
<right offset="0" />
</anchored>
<class>windowlistitem_generic</class>
<datasource>.elements</datasource>
<nohide />
<sortby mergerule="replace"><control>formattedname</control></sortby>
</windowlist>

This is the code i use to add elements
local nodeNewEntry = createWindow();

nodeNewEntry.open.setValue(sText);
nodeNewEntry.openclass.setValue(oClass);
nodeNewEntry.refreshDetails()

nodeNewEntry.refreshDetails();


function refreshDetails()
if self.open.getValue() == "" then
return;
end
local origNode = DB.findNode(self.open.getValue());
if origNode then
local origName = origNode.getChild("name").getValue();
local formattedName = DataManager.getCompleteName(origNode, openclass.getValue());

self.first_control.setValue(origName);
self.formattedname.setValue(formattedName);
end
end

Trenloe
February 11th, 2023, 13:04
NB If is use the sortby with formattedname, it doesn't work, but if I use first_control, everything goes well.
This is documented in the windowlist control in the Wiki here: https://fantasygroundsunity.atlassian.net/wiki/spaces/FGCP/pages/996645260/windowlist

Under the <sortby> definition it states: "Only string or number values can be used for sorting. " Formattedtext controls/values aren't the same as string controls/values and so don't work with <sortyby>.

Xarxus
February 11th, 2023, 13:39
Ops, formattedtext control is not string?
Wow, I could have banged my head on it for a lifetime without understanding it! Thank goodness I asked :D

Thank you very much Trenloe!