cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Want the oppurtunity to discuss enhancements to PTC products? Join a working group! X

sort a datatable on a column other than the key

rmiller-9
6-Contributor

sort a datatable on a column other than the key

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

5 REPLIES 5

You can sort it Server Side, with Sort snippet.

rmiller-9
6-Contributor
(To:CarlesColl)

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.

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 });

rmiller-9
6-Contributor
(To:CarlesColl)

That may work.  In the interim, I've taken a slightly different approach by adding a different column to act as the key.  Unfortunately, it is sorting 'ascending' rather than 'descending.'  Is there a way to toggle the grid column to sort 'descending' upon mashup load?  Otherwise I have to click the column header for the proper sort order each time the mashup is reloaded.

rob

I don't think so

Announcements


Top Tags