Wednesday, April 05, 2006

OpenLaszlo - how to sort a list

It is possible to sort a list in OpenLaszlo if the list is created from a datapath. (I haven't tried in any other case, but why create a list without a datapath??).

Here's the code:

<canvas debug="true">
<dataset name="myData">
<myXML>
<person name="Alice"/>
<person name="Mary"/>
<person name="Bob"/>
<person name="Susan"/>
</myXML>
</dataset>

<simplelayout axis="y"/>
<list name="myList">
<textlistitem name="item" datapath="myData:/myXML[1]/person[1]/@show"/>
</list>

<button text="descending" y="70">
<method event="onclick">
myList.item.datapath.setOrder("@name", "descending");
</method>
</button>
<button text="ascending" y="70">
<method event="onclick">
myList.item.datapath.setOrder("@name", "ascending");
</method>
</button>

<button text="fill" y="100">
<method event="onclick">
myList.item.setDatapath("myData:/myXML[1]/person/@name");
</method>
</button>
</canvas>

Notice that the original data is not sorted alphabetically. When you hit the "fill" button, the list is filled with the data. Then you can use the sort buttons to sort the data up and down. Sorting is done on the datapath, not on the list itself. Neat! (I'm using lps-3.1.1 by the way, and this code example runs dandy).

0 Comments:

Post a Comment

<< Home