Community Tip - Your Friends List is a way to easily have access to the community members that you interact with the most! X
Dear community,
I would like to retrieve the last x (e. g. 10) records (by id) from a DataTable. This post nearly covers my problem but Streams do not suite my data and the second solution does not work because I have an additional filter. Here is what I thought should work:
var query = { "sorts": [ { "fieldName": "MessageId", "isAscending": false } ], "filters": { "type": "EQ", "fieldName": "Direction", "value": 2 } }; var entries = Things["MESMessageLogDT"].QueryDataTableEntries({ maxItems: 10, query: query });
MESMessageLogDT is the DataTable entity and I would like to get the last 10 records matching my filter criteria (Direction = 2), this is why I cannot simply take length - x.
However, the actual result is: The first 10 records but in descending order. So apparently the sequence of data processing is
while I need (and expected)
A workaround is this but the performance is poor and gets worse with every entry:
var entries = Things["MESMessageLogDT"].QueryDataTableEntries({ maxItems: 9999999, query: query }); entries = Resources["InfoTableFunctions"].TopN({maxItems:10, t:entries});
Is there any better approach?
Thanks
Benny
Stream entries come with oldest first y/n by default. DataTables unfortunately do not.
This is a design weakness in datatables for which at this time there is no way around.
at least I don't think there is a way around it.