3.0 beta 2

Select all rows - Performance problem

I have a grid with more than 7000 data entries and want to select all rows.
If I use the method
obj.setSelectedRows([0,1,....,6998,6999]);
it takes serveral minutes and the browser runs into a timeout.

Do you have any performance suggestions, how to fix the problem?

Claudia
September 8,
Any help with my problem?

It is really important to select all rows in a large grid..
Don't you have kind of workaround?
Claudia
September 14,
bump
DT
September 15,
Here is a possible workaround (seems to be much faster) -

obj.selectAllRows = function(){

    // save event handlers
    var onRowSelectedChanged = this.onRowSelectedChanged;
    var onRowStateChanged = this.onRowStateChanged;

    // cancel events
    this.onRowSelectedChanged = function(){return 1};
    this.onRowStateChanged = function(){return 1};

    this.setRowSelected(true);
    this.setRowState("selected");

    var i, rows = [], max = this.getRowCount();

    for (i=0; i<max; i++){
        rows.push(i);
    }

    this.setSelectedRows(rows);

    // restore event handlers
    this.onRowSelectedChanged = onRowSelectedChanged;
    this.onRowStateChanged = onRowStateChanged;

    // repaint the grid content
    this.refresh();

}


Should be something similar to un-select rows after that...
Alex (ActiveWidgets)
September 15,
It works great and MUCH faster!!! Thanx

But now I have the same problem, if I wan't to un-select all rows:

obj.selectNoRows = function(){ 

    // save event handlers 
    var onRowSelectedChanged = this.onRowSelectedChanged; 
    var onRowStateChanged = this.onRowStateChanged; 

    // cancel events 
    this.onRowSelectedChanged = function(){return 1}; 
    this.onRowStateChanged = function(){return 1}; 

    this.setRowSelected(false); 
    this.setRowState(""); 

    var i, rows = [], max = this.getRowCount(); 

    for (i=0; i<max; i++){ 
        rows.push(i); 
    } 

    this.setSelectedRows(rows); 

    // restore event handlers 
    this.onRowSelectedChanged = onRowSelectedChanged; 
    this.onRowStateChanged = onRowStateChanged; 

    // repaint the grid content 
    this.refresh(); 

}


The function does the unselection, but after this, if you want to select any row, there's no reaction and you have to try another one. Then it works.

Maybe a bug?

Claudia
September 18,
Claudia, Unselect all rows don't need the 'row' array creation, so you can replace all this code :
var i, rows = [], max = this.getRowCount();  
    for (i=0; i<max; i++){ rows.push(i); }  
    this.setSelectedRows(rows);

with just :
this.setSelectedRows([]);


Carlos
September 18,
Yes, exactly as Carlos said -

obj.selectNoRows = function(){

    // save event handlers
    var onRowSelectedChanged = this.onRowSelectedChanged;
    var onRowStateChanged = this.onRowStateChanged;

    // cancel events
    this.onRowSelectedChanged = function(){return 1};
    this.onRowStateChanged = function(){return 1};

    this.setRowSelected(false);
    this.setRowState("");
    this.setSelectedRows([]);

    // restore event handlers
    this.onRowSelectedChanged = onRowSelectedChanged;
    this.onRowStateChanged = onRowStateChanged;

    // repaint the grid content
    this.refresh();

}
Alex (ActiveWidgets)
September 18,
Hi,
I have also run into this performance problem when I want to select large numbers of rows, but not actually all of them.

For the sake of this example, I am trying to select 1999 of 2000 rows and the indices of these rows are in a javascript array called 'myRows'. Virtual mode is on, and there are only about 20 rows actually scrolled into view.

If I just call setSelectedRows(myRows), then the browser runs into a timeout, and I get a modal popup that asks me if I want to terminate the script (I'm using IE 7).

If I disable the onRowSelectedChanged handler as shown in the previous solutions in this thread then the timout does not occur, but unfortunately my selected rows never get highlighted - it looks like the selection is actually occurring, but there is no indication of it :(

If my grid contains less than about 1500 rows, then the timeout does not occur (CPU-load permitting). It looks very much as if the onRowSelectedChanged handler is being called for all the rows in the grid, not just the ones in the virtual window which actually need it to paint themselves.

Is there any way around this? Our application could potentially have very large datasets (~35K rows), of which any combination could be selected, so this is currently a bit of a showstopper for us.

Thanks in hope...
Sharon
May 16,
Most likely you need adding refresh() call at the end to repaint the grid.
Alex (ActiveWidgets)
May 16,
refresh() was being called already - it's definitely not that.

After much stepping though with the debugger, I worked out that the "selected" appearance was being set by the calculateRowState function which was in turn being called in the onRowSelectedChanged handler - which was, of course, supressed for the fast-select and hence no state change.

I have been able to work around this by explicitly calling setRowState for each of my selected rows, rather than needing the overhead of the full set of event handlers with all their extra calls to refresh(). So far it has not timed out in any of my tests on up to 10K rows, and if I run into the timeout at higher row counts then UI should be able to use window.setTimeout to yield the CPU in the middle of my loop if necessary.

For anyone else that runs into this in the future, the fast-select function is:

function FastSelectRows(grid, selectedRows)
{
    // Cache then supress selection event handlers. 
    var onRowSelectedChanged = grid.onRowSelectedChanged; 
    var onRowStateChanged = grid.onRowStateChanged;
    grid.onRowSelectedChanged = function() {return 1;}; 
    grid.onRowStateChanged = function() {return 1;}; 
       
    if (selectedRows.length == grid.getRowCount())
    {
        // All of of the grid is selected.
        grid.setRowSelected(true); 
        grid.setRowState("selected");
    }
     else
    {
        // At least some of the grid is unselected.
        grid.setRowSelected(false); 
        grid.setRowState("");
        for (var i in selectedRows)
        {
            grid.setRowState("selected", selectedRows[i]);    
        }
    }
    grid.setSelectedRows(selectedRows); 
                             
    // Restore the cached event handlers 
    grid.onRowSelectedChanged = onRowSelectedChanged; 
    grid.onRowStateChanged = onRowStateChanged;  
 }


Thanks anyway,
Sharon
May 17,

This topic is archived.

See also:


Back to support forum

Search

Version 2

Looking for AW 2.6 ?
The old site is here.