Javascript 如何更改extjs中特定列中的所有值?
我有一个带列的可编辑网格面板,我想在按下applyToAll按钮时将列中的每个值更改为相同的值。似乎没有任何api调用使我能够获取列中的所有值,甚至网格面板中的所有值Javascript 如何更改extjs中特定列中的所有值?,javascript,gridview,extjs,extjs3,extjs-grid,Javascript,Gridview,Extjs,Extjs3,Extjs Grid,我有一个带列的可编辑网格面板,我想在按下applyToAll按钮时将列中的每个值更改为相同的值。似乎没有任何api调用使我能够获取列中的所有值,甚至网格面板中的所有值 //Model that defines my column named fileName var colModel = new Ext.grid.ColumnModel([{ header:'File Name', dataIndex:'fileName' } ]); // Editable grid
//Model that defines my column named fileName
var colModel = new Ext.grid.ColumnModel([{
header:'File Name',
dataIndex:'fileName'
}
]);
// Editable grid panel:
var myGrid = new Ext.grid.EditorGridPanel({
store: store,
colModel: colModel,
clicksToEdit: 1,
autoWidth: true,
autoHeight: true
});
// Button that changes all the column names
var applyToAll = new Ext.Button({
text: "Apply to All",
handler: function(){
var record = myGrid.getSelectionModel().getSelected();
//Change the values of the column here somehow.
}
});
//Form which holds everything
var gridForm = new Ext.FormPanel({
id: 'mainForm',
frame: true,
items: [{
columnWidth: 0.6,
layout: 'fit',
items: [myGrid],
buttons: [applyToAll]
});
单击ApplyAll按钮时,如何更改列中的所有值?要知道选择了哪个单元格,请使用单元格选择模型
var myGrid = new Ext.grid.EditorGridPanel({
// ...
selModel: new Ext.grid.CellSelectionModel(),
// ...
});
然后,您可以调用存储区的每条记录并更改所需的值:
// Button that changes all the column names
var applyToAll = new Ext.Button({
text: "Apply to All",
handler: function(){
var record = myGrid.getSelectionModel().getSelected();
var row = myGrid.getSelectionModel().getSelectedCell()[0];
var col = myGrid.getSelectionModel().getSelectedCell()[1];
var column_name = myGrid.getColumnModel().getColumnAt(col).dataIndex;
myGrid.getStore().each(function(rec){
rec.set(column_name, myGrid.getStore().getAt(row).get(column_name));
});
}
});
我最终做了什么:
var myGrid = new Ext.grid.EditorGridPanel({
//...
//I needed RowSelectionModel for another portion of my code
selModel: new Ext.grid.RowSelectionModel()
//...
)};
var applyToAll = new Ext.Button({
text: "Apply to All",
handler: function(){
var record = myGrid.getSelectionModel().getSelected();
myGrid.stopEditing();
var gridStore = myGrid.getStore();
var records = gridStore.getRange(0, gridStore.getTotalCount());
for(var ii=0; ii<records.length; ii++){
var curRecord = records[ii];
curRecord.set('testCell', record.get('testCell'));
}
gridStore.removeAll(true);
gridStore.add(records);
myGrid.startEditing(0, 0);
}
});
var myGrid=new Ext.grid.EditorGridPanel({
//...
//我的代码的另一部分需要RowSelectionModel
selModel:new Ext.grid.RowSelectionModel()
//...
)};
var applyToAll=新建外部按钮({
文本:“适用于所有人”,
处理程序:函数(){
var record=myGrid.getSelectionModel().getSelected();
停止编辑();
var gridStore=myGrid.getStore();
var records=gridStore.getRange(0,gridStore.getTotalCount());
对于(var ii=0;ii