Skip to main content
6-Contributor
April 25, 2016
Question

sort a datatable on a column other than the key

  • April 25, 2016
  • 1 reply
  • 4017 views

I'd like to sort the results loaded to a datatable on the timestamp field, rather than the defaul sort based on the key field.  How do I do that?  I'm guessing that I'm missing a simple switch or selection box somewhere, but I didn't see it on the configure submenu of the widget.

Thanks,

rob

1 reply

1-Visitor
April 26, 2016

You can sort it Server Side, with Sort snippet.

rmiller-96-ContributorAuthor
6-Contributor
April 26, 2016

Looks like both 'sort' service snippets are for 'infotables' and i cant seem to get either to recognize the datatable.  Guessing they're not interchangable.  Any other recommendations to sort?  There aren't any default thingtemplate services that sort.

1-Visitor
April 27, 2016

You should be able to Sort the "DataTable" with Sort Snippets, just Query the datatable with the corresponding service, which will return an Infotable and then you will be able to sort it. You need to create a new Service which does both, something like this:

var result = Things["YourDataTableThingName"].QueryDataTableEntries({

  maxItems: undefined /* NUMBER */,

  values: undefined /* INFOTABLE*/,

  query: undefined /* QUERY */,

  source: undefined /* STRING */,

  tags: undefined /* TAGS */

});

result.Sort({ name: "fieldNameToSort", ascending: true });