PDA

View Full Version : Grid: Have colIndex and rowIndex, how to select the cell?



brunofin
22 Jul 2014, 10:41 AM
Hi all,

I have the rowIndex and colIndex of a cell which I want to edit its value (in a way almost like a renderer).

How can I edit its value? I can't find the correct methods for this.

Thanks

skirtle
22 Jul 2014, 3:03 PM
What do you mean by edit? As in show an editor?

http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.grid.plugin.Editing-method-startEdit

If by 'edit' you just mean change the value then see the source of startEdit for how to map co-ordinates to the corresponding column and record. You don't edit a cell as such, you just set the corresponding field on the record.

brunofin
23 Jul 2014, 5:22 AM
No, I don't want to show up an editor to the user, no user interaction.

What in fact happens is that there's a column which contains a value. This value is a primary key of another model, and what I need to do is to load this model and set the displayed value in the column to the property "name" of the loaded model. I am trying to use the renderer to achieve that:


{text: 'Modelo', dataIndex: 'model', filterable: true,
renderer: function(value, metaData, record, rowIndex, colIndex, store) {
MyApp.model.Model.load(value, {
scope: this,
success: function(record) {
console.log(record.data.name); // I need to return this value
}
});
return '';
}},

But as the method load is asynchronous, I can't return the value that I need. So I was trying to find a way to set this value in the success function.

Any ideas of how to do that?

skirtle
23 Jul 2014, 7:40 AM
When the model is loaded from the server, store it somewhere that the renderer can get to it then refresh the grid row (refreshNode).

Exactly how you store the models is up to you. You could add them to the row's model, or you could have a cache on the grid. It depends on whether they're shared and how long you want to keep them around.

Also keep in mind that things like sorting, filtering or editing will cause a refresh and that will re-run the renderer. Your strategy for storing the extra models needs to take that into account. It'd probably be better to manage the extra load requests outside the renderer, perhaps in reaction to the store loading or the grid view being refreshed.