« [Tip] How to let your solution know the client is headless | Main | [Servoy World 2005] it2be_menubar plugin and more :) »

August 19, 2005

[Tip] Looping through rows

by Marcel Trapman
www.it2be.com

Everybody needs to, from time to time, loop through a set of rows in order to search for a particular value or a row. This is very easy but can have, when not handled the right way, great impact on the performance of your solution.

Quite often the looping is done via the following method:

Var size = controller.getMaxRowIndex();

For ( var i = 1 ; i <= size ; i++ ) {
Controller.setRowIndex(i);

//do your thing
}

Using this creates at least one but likely 2 performance issues:

1. When the form is shown the screen needs to be repainted every single step because you ‘fysically walk’ through rows on the screen...
2. If you attach a method to the recordSelection event, stepping through the rows will cause the method to be fired every step...

So, knowing that, you will ALL, of that I am sure, use the below method from now on:

Var set = foundset;
Var size = set.getSize();

For ( var i = 1 ; i <= size ; i++ ) {
Var row = set.selectRecord(i);

//do your thing
}

Notice that not only did I copy the foundset to a variable called ‘set’ but I also copied the contents of the row to the variable ‘row’. This way you do everything on the foundset without touching the controller. Please make sure, when referencing to a column you now reference to row.column instead!! Otherwise your result won’t be what you expected it to be ☺

Hope this helps a little in solving potential (or actual) performance issues,

Marcel

| Posted by IT2Be on August 19, 2005 at 04:54 AM in Tips | Permalink

Comments

Just a little adjustment:

For ( var i = 1 ; i <= foundset.getSize() ; i++ ) {
var row = foundset.selectRecord(i);

//do your thing
}

or else the method will stop after 200 records!

Posted by: Harjo Kompagnie | Aug 20, 2005 8:14:54 AM

btw: this is allready tip here:
http://www.servoymagazine.com/home/2005/02/tip_looping_thr.html. From myself. haha

:-)

Posted by: Harjo Kompagnie | Aug 20, 2005 8:18:59 AM

var row = foundset.selectRecord(i); OR
var row = foundset.getRecord(i);

??

Thanks

Posted by: Hameed | Oct 20, 2005 7:08:02 AM

??

Posted by: Marcel Trapman | Oct 20, 2005 7:10:49 AM

Post a comment