On 6 Sep 2009, at 17:15, gregg wrote:
> I need a way to sort my query results. The basic use pattern is
> this: populate a table from the query results, and allow the user to
> reorder by drag and drop of the table headers. A while back I hacked
> up some code to do this with ordinary Javascript arrays, but rdfQuery
> looks like a much better way to deal with my sparql query results.
> But looking at the result of running a query against an rdfQuery
> databank, it looks like the results are a DOM structure. Is that
> correct? Is there a best-practice method of sorting data managed by
> rdfQuery?
You can certainly use rdfQuery if you're doing a DESCRIBE or CONSTRUCT
SPARQL query (rdfQuery operates over RDF, not the results from SELECT
SPARQL queries).
An rdfQuery object (eg created with $.rdf() or from RDFa with $
('body').rdf()) is a bit like an array that contains objects with
properties that are bound to the variables that you've used in your
queries. It's not a DOM.
To sort the data you've selected with a rdfQuery object, I think the
easiest thing would be to turn the rdfQuery object into an array with
the .get() method, and then use .sort() on that array.
Or, if you're displaying the data in a table you might want to look at
something like the Datatables jQuery plug-in (http://
www.datatables.net/) which will do sorting etc for you.
I hope that gives you some pointers. Let us know if you have
particular questions.
Cheers,
Jeni
--
Jeni Tennison
http://www.jenitennison.com