Sorting of DataTable

5,839 views
Skip to first unread message

Rune V. Sjoen

unread,
Dec 1, 2009, 8:34:41 AM12/1/09
to Google Visualization API
Is there any way to control the direction of sort when executing
datatable.sort(columnindex) ? Whenever I do this the table is sorted
on the correct column index but it is sorted ascending. I would like
to sort it descending.

I could simply invert it after sorting but that seems very ugly.

Gerard Flanagan

unread,
Dec 1, 2009, 8:45:10 AM12/1/09
to google-visua...@googlegroups.com
eg.

dt = new google.visualization.DataTable(mydata, 0.6);
dt.sort({column: 1, desc: true});


Pegasusrjf

unread,
Dec 2, 2009, 8:16:45 AM12/2/09
to Google Visualization API
It appears that the code you show below will work, according to the
API documentation.

http://code.google.com/apis/visualization/documentation/reference.html

If the datatable is coming from a Query statement, then you could sort
the return dataset during the query operation.

Rune V. Sjøen

unread,
Dec 2, 2009, 8:19:24 AM12/2/09
to google-visua...@googlegroups.com
It works very well, I would sort it with a Query but this table has multiple columns and is used for multiple charts, the columns needs to be sorted differently based on the chart type and I try to avoid doing the query more than once.

Thanks
--
Rune V. Sjoen
You always pass failure on the way to success


--

You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To post to this group, send email to google-visua...@googlegroups.com.
To unsubscribe from this group, send email to google-visualizati...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-visualization-api?hl=en.



Pegasusrjf

unread,
Dec 2, 2009, 8:46:07 AM12/2/09
to Google Visualization API
could you not specify a DataView on the first query results, and then
sort the Dataview before you draw the chart?

Also sending a second query with a different order shouldn't be an
issue as it would be cached query results (at least that is my
understanding).
> > google-visualizati...@googlegroups.com<google-visualization-­api%2Bunsu...@googlegroups.com>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/google-visualization-api?hl=en.- Hide quoted text -
>
> - Show quoted text -

Rune V. Sjoen

unread,
Dec 4, 2009, 10:26:20 AM12/4/09
to Google Visualization API
I needed to change the table before sorting it, and dataviews are read-
only. But
for pure sort and display that would probably work better.
> > >http://groups.google.com/group/google-visualization-api?hl=en.-Hide quoted text -
Reply all
Reply to author
Forward
0 new messages