How to reduce foundset to a subset based on index range

What is a good way to reduce a foundset to a subset based on an index range from the original foundset? For example, if you have a foundset of 1,000 records, how can you reduce that foundset to only contain records that originally had an index of 550 through 875?

Dean

Find/search of if those records have something in common. If it’s only the index you can work with, I’d omit the records you want and then invert the foundset (since there’s less records you actually want). Offcourse you can also just omit every record you don’t want.

Paul

Yes, I am only working with index numbers. Okay, so looping through and omitting is the best approach. Thank you for the quick response.

Dean

might there be a way to grab those lines from the index of pk’s in the FS (and then just send it back as a query)? would beat looping if the FS is large. Just thinking conceptually … this sort of thing exceeds my personal coding skills.

kazar

I was wondering about that also.

Dean

With regard to looping, the following seems to work well:

//load all records of the foundset without touching ui
for(var i = 0; i <= foundset.getSize(); i++)
{
	foundset.getRecord(i);
}
//process records from last to first (thanks to a prior post by Johan Compagner)
for(var i=foundset.getSize(); --i>0;)
{
   var record = foundset.getRecord(i);
   if (record.test_id >= globals.start_index && record.test_id <= globals.end_index)
   {
           foundset.omitRecord(i);      
   }
}
foundset.loadOmittedRecords();
foundset.sort('test_id asc');

Dean

How can resulting subset be converted to be the new foundset?

Dean

If you don’t want to do the looping yourself, you can also do something like this:

var _ds = databaseManager.convertToDataSet(foundset);
var _array = _ds.getColumnAsArray(1);
_array = _array.slice(549, 874);

foundset.loadRecords(databaseManager.convertToDataSet(_array));

Joas:
If you don’t want to do the looping yourself, you can also do something like this:…

Nice ! :D

Very nice!

Thank you,

Dean