How do I change individual cell values in a Dojo datagrid

Napoleon picture Napoleon · May 1, 2011 · Viewed 12.2k times · Source

I have a dojo datagrid which cells I will like to change at will depending on changes in user choice. The store used for the grid is populated from multiple database tables. This particular feature is very central to the application I am working on as there are a lot of calculations which results affects other cells in the grid.

I figure it will be something like get the grid, get the row based on an index and then get the cell by name. However I have not been able to figure how to do this.

Answer

Alex Cheng picture Alex Cheng · May 3, 2011

To change the data displayed in a dojo datagrid, you need to update the grid's store instead. Suppose that you want to edit the cell of column 'Name' in the current selected row, first get the row's index:

var index = grid.selection.selectedIndex;

Then get the row:

var item = grid.getItem(index);

Update the cell:

var store = grid.store;
store.setValue(item, 'Name', 'Your value');

Finally, update the grid's display

grid.update();