287
edits
(add new sort features) |
|||
Line 175: | Line 175: | ||
This method returns a result which implements nsIXULTemplateResult for a given id. This may be convenient instead of using the DOM or tree APIs to get information about a particular generated result. | This method returns a result which implements nsIXULTemplateResult for a given id. This may be convenient instead of using the DOM or tree APIs to get information about a particular generated result. | ||
==Sorting== | |||
Sorting of results may be done by using the sort and sortDirection attributes. | |||
<listbox datasources="..." ref="..." | |||
sort="key" sortDirection="ascending"/> | |||
The sort attribute is a key or keys to sort on. It may be a template variable like '?name'. For RDF queries using the simple syntax, it may be the full predicate prefixed with 'rdf:'. For example, 'rdf:http://home.netscape.com/NC-rdf#Name'. | |||
Multiple sort keys may be used, seperated by spaces. | |||
The sortDirection attribute should be set to 'ascending', 'descending' or 'natural'. This last value is the default and displays results in no particular order, although they will appear in Seq order for RDF datasources. | |||
Trees also support sorting using a similar syntax, however the sort and sortDirection attributes should be placed on <treecol> elements instead. | |||
The sortActive attribute set to true indicates which column is actively sorted. | |||
The XUL Sort Service may be used to sort a XUL element: | |||
var xs = Components.classes["@mozilla.org/xul/xul-sort-service;1"]. | |||
getService(Components.interfaces.nsIXULSortService); | |||
xs.sort(element, "?name", "ascending"); | |||
where the arguments to the sort function are the element to sort, the sort key (or multiple keys separated by spaces), and the sort direction. | |||
You may also sort non-template generated content using the sort function. In this case, the children of 'element' are sorted and the sort key is an attribute of those children to sort by. |
edits