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

sort a datatable on a column other than the key

rmiller-9
Participant

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

Re: sort a datatable on a column other than the key

You can sort it Server Side, with Sort snippet.

Re: sort a datatable on a column other than the key

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.

Re: sort a datatable on a column other than the key

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

Re: sort a datatable on a column other than the key

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

Re: sort a datatable on a column other than the key

I don't think so

Announcements

Check out the upcoming Expert Session: Understanding ThingWorx Navigate Licensing in Community "Customer Events" section.