How to read and set a value of a specific cell in an ExtJS Grid?

不想你离开。 提交于 2019-12-18 12:38:09

问题


I am beginning with ExtJS. I am trying to read a value from a cell that is selected
I use an EditorGrid and the store looking like that :

my_store = new Ext.data.JsonStore({
    root: 'topics',
    totalProperty: 'totalCount',
    idProperty: 'details_id',

    fields: [
        {name : 'index',    type : 'int'},
        {name : 'inactive', type : 'int'},
        {name : 'c_1',      type : 'string'},
        {name : 'c_2',      type : 'string'},
        {name : 'c_3',      type : 'string'},
        {name : 'c_4',      type : 'string'}
    ],
    proxy: new Ext.data.ScriptTagProxy({
        url: 'my_proxy_url'
    })
});

As of now, this is what I use to retrieve the rows and columns of the selected cell :

var column = grid.getSelectionModel().selection.cell[0];
var row    = grid.getSelectionModel().selection.cell[1];

How can I read the value of a selected cell in the grid and change this value ?


回答1:


It entirely depends upon your selection model. With a RowSelectionModel you can get the Record of the selected row like thus:

var sel_model = grid.getSelectionModel();
var record = sel_model.getSelection()[0];

Then all you need do is use the set() method:

record.set("c_1","Test");

Of course, with an EditorGridPanel you're supposed to assign editing to controls and not directly.




回答2:


it has been explained quite well here http://atechiediary.blogspot.in/2013/06/extjs-grid-update-values-of-elements-in.html




回答3:


@Llyod

as per your answer,

It entirely depends upon your selection model. With a RowSelectionModel you can get the Record of the selected row like thus:

var sel_model = grid.getSelectionModel();
var record = sel_model.getSelection()[0];

Then all you need do is use the set() method:

record.set("c_1","Test");

Of course, with an EditorGridPanel you're supposed to assign editing to controls and not directly.

this works, But what if i want to accesses the value of cell by using column value (e.g. 4 or 5) instead of column name. Is it possible to do the same



来源:https://stackoverflow.com/questions/2447401/how-to-read-and-set-a-value-of-a-specific-cell-in-an-extjs-grid

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!