Skip to main content

How to toggle all checkboxes for a dojo Enhanced Grid


Dojo Enahnced grid provides multiple ready to use event handlers for handling row operations like onSelect, onAdd, onDelete. It also provides a way to select or deselect all rows of a grid via the dojo's indirectselection plugin. Selection can be radio button based (one row at a time) or checkbox based(multi row selection).

If you need to select all rows and then prevent further de-selection  of individual rows, there isn't a standard function to disable all checkboxes of the grid.

Here's a screenshot of what I'm talking about:

//toggleCheckBoxesForEnhancedGrid: 
//This function will select all checkboxes 
//and disable it or deselect all and enable it
//Params:
//gridName: id of the grid
//flag: true or false
function toggleCheckBoxesForEnhancedGrid(gridName,flag){
    var grid = dijit.byId(gridName);
    for(var i = 0; i < grid.rowCount; i++)
    {
        //first select the checkbox for row number i
        grid.selection.setSelected(i, flag);
        //now prevent de-selection of checkbox by disabling it
        grid.rowSelectCell.setDisabled(i, flag); 
    }
}

The above function uses the enhanced grid's "rowSelectCell" feature to enable or disable a checkbox shown on every row of the grid.