How to reduce foundset to a subset based on index range

Questions, tips and tricks and techniques for scripting in Servoy

How to reduce foundset to a subset based on index range

Postby Westy » Thu Jul 09, 2009 4:54 pm

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
Westy
 
Posts: 852
Joined: Fri Feb 13, 2004 5:27 am
Location: Lynnfield, Massachusetts USA

Re: How to reduce foundset to a subset based on index range

Postby pbakker » Thu Jul 09, 2009 5:08 pm

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
pbakker
 
Posts: 2822
Joined: Wed Oct 01, 2003 8:12 pm
Location: Amsterdam, the Netherlands

Re: How to reduce foundset to a subset based on index range

Postby Westy » Thu Jul 09, 2009 5:20 pm

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
Westy
 
Posts: 852
Joined: Fri Feb 13, 2004 5:27 am
Location: Lynnfield, Massachusetts USA

Re: How to reduce foundset to a subset based on index range

Postby kazar » Thu Jul 09, 2009 6:13 pm

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
User avatar
kazar
 
Posts: 367
Joined: Sat Sep 13, 2003 9:59 pm
Location: New York City

Re: How to reduce foundset to a subset based on index range

Postby Westy » Thu Jul 09, 2009 9:46 pm

I was wondering about that also.

Dean
Westy
 
Posts: 852
Joined: Fri Feb 13, 2004 5:27 am
Location: Lynnfield, Massachusetts USA

Re: How to reduce foundset to a subset based on index range

Postby Westy » Thu Jul 09, 2009 9:55 pm

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

Code: Select all
//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
Westy
 
Posts: 852
Joined: Fri Feb 13, 2004 5:27 am
Location: Lynnfield, Massachusetts USA

Re: How to reduce foundset to a subset based on index range

Postby Westy » Thu Jul 09, 2009 10:08 pm

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

Dean
Westy
 
Posts: 852
Joined: Fri Feb 13, 2004 5:27 am
Location: Lynnfield, Massachusetts USA

Re: How to reduce foundset to a subset based on index range

Postby Joas » Fri Jul 10, 2009 9:20 pm

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

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

foundset.loadRecords(databaseManager.convertToDataSet(_array));
Joas de Haan
Yield Software Development
Need help on your project? yieldsd.com
User avatar
Joas
Site Admin
 
Posts: 842
Joined: Mon Mar 20, 2006 4:07 pm
Location: Leusden, NL

Re: How to reduce foundset to a subset based on index range

Postby ROCLASI » Fri Jul 10, 2009 11:06 pm

Joas wrote:If you don't want to do the looping yourself, you can also do something like this:...


Nice ! :D
Robert Ivens
SAN Developer / Servoy Valued Professional / Servoy Certified Developer

ROCLASI Software Solutions / JBS Group, Partner
Mastodon: @roclasi
--
ServoyForge - Building Open Source Software.
PostgreSQL - The world's most advanced open source database.
User avatar
ROCLASI
Servoy Expert
 
Posts: 5438
Joined: Thu Oct 02, 2003 9:49 am
Location: Netherlands/Belgium

Re: How to reduce foundset to a subset based on index range

Postby Westy » Sat Jul 11, 2009 12:44 am

Very nice!

Thank you,

Dean
Westy
 
Posts: 852
Joined: Fri Feb 13, 2004 5:27 am
Location: Lynnfield, Massachusetts USA


Return to Methods

Who is online

Users browsing this forum: No registered users and 41 guests