From MozillaWiki
Jump to: navigation, search

XUL Sort Service Improvements

The XUL Sort Service is used for sorting content built by a content template builder, although not a tree builder. It has two purposes, figure out where to insert a new generated item into a existing container, and change the sort key and/or direction of an existing container.

The code is large and complex, considering that the tree sorting built into the tree builder has about 90% of the same functionality, but with only 10% as much code.

The sort service also only works with RDF datasources.

Thus, some work will be done to improve the sort service.

  1. Move the sort inserting code directly into the content builder. Eventually, it may be possible to sort results first and then insert them all sorted.
  2. Make the sort inserting code and the container sort algorithms use the query processor for sorting such that they work on all datasources.
  3. Make how one specifies the sort info consistent, as described below.
  4. Simplify the sort code

Bug 335122 tracks this work.


The following attributes will be involved in sorting:

sort="?key1 ?key2 ..."

Specifies the sort keys to be used. One or more may be specified. For template-built content, the keys are expected to be identifiers used in the template, either of the variable form such as ?name, or a predicate such as rdf:http://www.example.com/name. A query processor may also support other values. In the case of RDF, keys that are RDF predicates without the rdf: prefix may be used also.


This is obsolete but is equivalent to specifing one sort key.


This is obsolete but is equivalent to specifing the second sort key. Thus, sortResource and sortResource2 are the same as sort="sortResource sortResource2".


The direction of the sort.


Indicates if sorting is done separately between separators.


Set automatically to determine how many static children there are. These static children are not sorted.


True if static content is placed after generated content, and false is static content should be placed before generated content. I don't think this actually works currently anyway, so no need to support it necessarily in the future.

Tree Content

For content trees, the sort attribute may be specified on a column. When sorted, the sort service will update the column where the sort attribute matches the sort key by setting the sortDirection and sortActive attributes. This will update the column sort indicator as necessary.

Special Sort Resources

  • The form resource?sort=true can be handled directly in the query processor.
  • The form resource?collation=true isn't used anywhere so it will be removed.

Sorting Non-Templates

For an element that doesn't have a template, support will be added to allow it to be sorted using the sort service's Sort method. If the element implements nsIDOMXULSelectControlElement, its items will be sorted. For trees, the treeitems will be sorted Otherwise, the children of the element will be sorted. The sort key is an attribute on those items to sort by.

If an item to be sorted has a container attribute set to true, it will be sorted recursively.