3.2.0

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
November 28,
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
November 29,
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=0; i<rSelected.length; i++) {
        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; j <obj.getRowCount(); j++){
        if (hash[j] != 1){
            newSelectedRows.push(j) ;
        } 
         }
    }else{
         for (k=0; k<rIndices.length; k++){
        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; j <obj.getRowCount(); j++){
        newSelectedRows.push(j) ;
    }
    
    obj.setSelectedRows(newSelectedRows);
    obj.refresh();

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

}
Colin P
May 16,

This topic is archived.

See also:


Back to support forum