Hi,
I have some lists with thousands of records and while I can sort by their ID descending to have the most recent (i.e. highest ID) record at the top of the list, I would rather sort ascending and then show the most recent record as highlighted with the rest of the list going up the page. Make sense?
Any ideas how to make this happen?
Thanks.
Servoy retrieves records in blocks of 200, starting with the first 200 returned by your query. It retrieves the next block of 200 once you select the 200th record from the previous batch. This works great for most situations but I think it will be either very tricky or impossible to make it do exactly what you describe here. If I understand your requirement, you would want Servoy to go retrieve the next batch of records when the user selects the FIRST record in the currently displayed list (instead of the LAST). I know of now way of achieving that.
Perhaps someone else knows a way…
Here’s some sample code.
notes:
In order to go all the way down though a foundset that’s larger that 200 you can loop through the foundset. A for loop will trigger the next 200 blocks until the last block is reached.
However, this can be slow because it basically kills the "200 block’ optimalisation.
One way to avoid this , is doing a query on the max pk, substract something like 100, doing a ‘>’ find, resulting in a small foundset with approx 100 latest records to continue with.
Having said all this , I would still go for desc sort with latest record in top.
var vQuery = "SELECT max(company_id) FROM s_companies"
var vDataset = databaseManager.getDataSetByQuery(controller.getServerName(), vQuery, null, 1)
var vMaxPk = vDataset.getValue(1,1);
vMaxPk -= 100;
controller.find()
company_id = '>'+vMaxPk
controller.sort('company_id asc')
controller.search()
for (var i=1 ; i<=foundset.getSize() ; i++)
{
foundset.setSelectedIndex(i)
}