:: Forum >> Version 1 >>

Toggle All

I know how to do a select All.

But how can I do a toggle all, ie turn every row off that is on and on that is off.

Thanks.
Dale Fraser
Monday, November 28, 2005
Any ideas?

Somehow should be able to loop through each entry check it's current state and reverse it, but I can't figure it out.
Dale Fraser
Tuesday, November 29, 2005
I added three function to my code to do exactly this (including selectAll)

Each function is called by a button and/or hot key.

function invertSelection() {
    var 
rSelected obj.getSelectedRows();

             
// clear all if all selected
    
if (rSelected.length == obj.getRowCount()) {
        
obj.setRowSelected( );
        
obj.refresh();
        return;
    }
    
             
//CREATE HASH OF ALL SELECTED ROWS
    
var hash = new Object();
    for (var 
i=0i<rSelected.lengthi++) {
        if (
hash[rSelected[i]] != 1)    {
            
hash[rSelected[i]] = 1
        
}
    }


    var 
newSelectedRows = new Array();
    var 
rIndices obj.getRowIndices();
             
             
//CREATED AN ARRAY OF UNSELECTED ROWS
             // NOTE: DIFFERENT LOGIC IF ROWS HAVE BEEN SORTED
    
if (""==rIndices||null==rIndices ){
         for (
j=0<obj.getRowCount(); j++){
        if (
hash[j] != 1){
            
newSelectedRows.push(j) ;
        } 
         }
    }else{
         for (
k=0k<rIndices.lengthk++){
        if (
hash[rIndices[k]] != 1){
            
newSelectedRows.push(rIndices[k]) ;
        } 
         }
    }
 
    
deSelectAll(); // DESELECT ALL ROWS
    
obj.setSelectedRows(newSelectedRows); //SET NEW ROWS SELECTED
    
obj.refresh();

    
grid2.focus(); // grid2 IS THE NAME OF MY GRID
}

function 
deSelectAll() {
    
obj.setSelectedRows([]);
    
obj.clearSelectionModel();
    
obj.refresh();
    
grid2.focus(); // grid2 IS THE NAME OF MY GRID
}

function 
selectAll(){
    var 
newSelectedRows = new Array();

    for (
j=0<obj.getRowCount(); j++){
        
newSelectedRows.push(j) ;
    }
    
    
obj.setSelectedRows(newSelectedRows);
    
obj.refresh();

    
grid2.focus(); // grid2 IS THE NAME OF MY GRID

}
 
Colin P
Tuesday, May 16, 2006



This topic is archived.

Back to support forum

Forum search