views:

243

answers:

0

I have a menu of checkbox menu table column names and would like the checking/unchecking of the column name to result in the table column being hidden or shown. I would like to be able to get the column to change via it's cell.name property rather than it's index.

Currently, I am accomplishing this by generating an associative array of cell.name -> index after creating the grid and on any onMoveColumn events. Ideally, I could just ask for the index or the cell from the grid? Is there a way to do this with the dojox.grid.DataGrid?

Ideally, I'm looking for a direct call to the DataGrid.

Here's my current approach:

function buildColMenus(...) {
    ...
    for(...)
      columnMenu.addChild(new dijit.CheckedMenuItem({id: [...], label: ..., checked: true, onChange: columnMenuChange})));
}

function mapGridColumnsToIndices(dataGrid) {
    var gridColNameToIndex = [];
    dojo.forEach(dataGrid.layout.cells, function(cell, index) { gridColNameToIndex[cell.name] = index; });
    return gridColNameToIndex;
}

function columnMenuChange() {
    ...
    var colNameToIndex = mapGridColumnsToIndices(grid);
    grid.layout.setColumnVisibility(colNameToIndex[this.label], this.checked);
}