PDA

View Full Version : how to access original object on grid row select?



kchiu
16 Nov 2009, 9:32 PM
Hi,

Does anyone know of the right way to obtain the original data object for a GridPanel's selected row?

I see that Ext.grid.RowSelectionModel has a 'rowselect' event defined as follows:


rowselect : ( SelectionModel this, Number rowIndex, Ext.data.Record r )

So inside the rowselect handler, I do the following to get that row's data object:


rowselect: function(smObj, rowIndex, record) {
var dataObj = record.data;
// ... directly edit dataObj as required
// ... eg. dataObj.property_A = 'updated value'
// ... but changes appear local to GridPanel's datastore only


The original data object is shared across various data structures, and I want the changes to be visible in those data structures. However, after editing dataObj, the changes are only visible locally at the GridPanel: ie. I can select another row, then reselect the modified row, and see the changed values; but when I need to view that shared object from another data structure, the changes don't appear - ie. the original data object is unchanged.

After a bit of investigation, it looks like record.data is actually a copy of the original data object, so it's the wrong one to edit. And after a bit more debugging through Firebug, I found that Ext.data.Record contains a 'json' property which appears to be the original data object. So I tried the following, and now the modifications do change the original data object:


rowselect: function(smObj, rowIndex, record) {
var dataObj = record.json;
// ... directly edit dataObj as required
// ... eg. dataObj.property_A = 'updated value'
// ... changes now appear on the original data object



However, record.json isn't mentioned in the API docs, and I want to avoid relying on undocumented implementation details.

So my question: is record.json the correct way to get the original data object in a rowselect event? And if not, what is the right way?

thanks a lot, regards.

ajohan75
16 Aug 2010, 6:18 AM
use the data api.

record.get and record.set

its in the data documentation. good luck.