How do I sort content?

You can sort data as long as it is generated from RDF. It is most common to sort content in a tree, however you can sort any template-generated content.

You can use the sortResource attribute to specify a resource to sort by. Use the sortDirection attribute to specify the direction to sort by. Both attributes must be present to have sorted data.

The following example demonstrates sorting content:

<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
<window id="sort-window" title="Sort Example"
function changeSort()
  // get the box to sort
  var box = document.getElementById("info");
  // if the sort direction is descending, change it to ascending.
  // Otherwise, set it to ascending.
  if (box.getAttribute("sortDirection") == "descending")
  else box.setAttribute("sortDirection","descending");
  // you must rebuild the content after changing sort information
<button label="Reverse" oncommand="changeSort();"/>
<vbox id="info" datasources="animals.rdf"
      ref="" flex="1"
      sortResource="" sortDirection="ascending">
    <label uri="rdf:*" value="rdf:"/>

In this example, data is sorted by name, as indicated by the sortResource attribute. However, any property may be used, even if it isn't displayed.

Copyright © 1999 - 2005