Extjs 4.0.7,编辑器网格-如何获得更新的单元格值?
我需要在控制器中获取(检索)更新的单元格值。(MVC) 所以我试过这个Extjs 4.0.7,编辑器网格-如何获得更新的单元格值?,extjs,grid,extjs4,Extjs,Grid,Extjs4,我需要在控制器中获取(检索)更新的单元格值。(MVC) 所以我试过这个 var modified = this.getItemGrid().getStore().getUpdatedRecords(); console.log(modified); // return [] empty array var modified = this.getItemList_Store().getUpdatedRecords(); console.log(modified); // return [] em
var modified = this.getItemGrid().getStore().getUpdatedRecords();
console.log(modified); // return [] empty array
var modified = this.getItemList_Store().getUpdatedRecords();
console.log(modified); // return [] empty array
但它总是返回空数组,即使我更新了一些单元格值
有人知道我做错了什么吗
这是我的部分视图代码
Ext.define("App.view.orders.ItemList_view", {
extend: "Ext.grid.Panel",
alias: "widget.itemList_view",
plugins: [
Ext.create('Ext.grid.plugin.CellEditing', {
clicksToEdit: 1
})
],
initComponent: function () {
this.store = "ItemList_store";
this.columns = [
{
xtype: 'checkcolumn', text: "Ship", width: 50, dataIndex: "DR"
},
{ header: "test", width: 100, dataIndex: "test",
editor: {
xtype : 'textfield'
}
}
];
this.selModel = Ext.create("Ext.selection.CheckboxModel");
//this.selModel = Ext.create("Ext.selection.CellModel"); // It does not works either.
this.callParent(arguments);
},
.
.
.
谢谢大家!
[编辑]
非常感谢您的回答!我还有一些关于编辑器网格的问题
它与Ext3有很大不同。所以我现在很困惑:(
Q1.如何收集已编辑的记录数据(单击按钮一次)?
更改网格单元后激发的事件。
但我希望在单击“更新已编辑单元格”按钮后收集已编辑的网格记录,并希望同时更新所有记录
在Ext3中,我喜欢这样
(button) click : function(){
var modified = mygridStore.getModifiedRecords();
var recordsToSend = [];
Ext.each(modified, function(record){
recordsToSend.push(record.data);
});
var grid = Ext.getCmp('grid');
grid.el.mask('Updating','x-mask-loading');
grid.stopEditing();
recordsToSend = Ext.encode(recordsToSend);
Ext.Ajax.request({
url : '/test/test',
params : {
data : recordsToSend
},
success : function(response){
grid.el.unmask();
alert(response.responseText);
mygridStore.commitChanges();
},
failure : function(response){
mygridStore.rejectChanges();
}
});
}
如何更改Extjs4的代码
Q2。我仍然不知道如何找到已更改的checkcolumn。
我尝试了这个,但我不为checkcolumn工作(当然,我在更改后测试了checkbox)
-
Q3。当我单击要编辑的单元格时,会在--;中显示一些HTML标记。
非常感谢您的帮助。非常感谢您宝贵的时间!编辑(单元格编辑或行编辑)在完成编辑之前,不要将其值提交到存储区-这意味着按ENTER键或通过单击页面上的其他位置模糊活动单元格编辑器,或单击行编辑器窗体上的save按钮
如果您在编辑器中读取更新的值的目的是执行某种验证,我建议您只需在网格控制器中侦听validatedit
事件,如下所述
此事件传递给处理程序的第二个参数包含有关编辑的大量数据,您可以使用这些数据执行验证。如果编辑未通过验证,您可以从处理程序返回false
,celleditor中的值将恢复为其原始值。validatedit
事件将触发从编辑器网格本身添加事件处理程序,以便在控制器中为其添加事件处理程序,如下所示:
Ext.define('MyApp.controller.MyController', {
init: function() {
this.control({
'mygridpanel': {
validateedit: function(plugin, edit) {
// silly validation function
if (edit.value != 'A Valid Value') {
return false;
}
},
},
});
},
});
// myGrid is a reference to your Ext.grid.Panel instance
if (myGrid.editingPlugin.editing) {
var value = myGrid.editingPlugin.getActiveEditor().field.value
console.log('value: ' + value);
}
checkchange: function (column, rowIndex, checked) {
var record = store.getAt(rowIndex),
state = checked ? 'checked' : 'unchecked'
console.log('The record:');
console.log(record)
console.log('Column: ' + column.dataIndex);
console.log('was just ' + state)
}
但是您应该查看上面的链接,以查看我命名为edit
的第二个参数中可用的所有不同对象
validatedit
事件在记录提交到存储区之前触发-在用户已单击ENTER
或模糊编辑器之后,即在编辑器关闭时
如果您试图在celleditor开始关闭之前获取其值,例如,出于验证以外的原因,您可以获取活动celleditor的值,如下所示:
Ext.define('MyApp.controller.MyController', {
init: function() {
this.control({
'mygridpanel': {
validateedit: function(plugin, edit) {
// silly validation function
if (edit.value != 'A Valid Value') {
return false;
}
},
},
});
},
});
// myGrid is a reference to your Ext.grid.Panel instance
if (myGrid.editingPlugin.editing) {
var value = myGrid.editingPlugin.getActiveEditor().field.value
console.log('value: ' + value);
}
checkchange: function (column, rowIndex, checked) {
var record = store.getAt(rowIndex),
state = checked ? 'checked' : 'unchecked'
console.log('The record:');
console.log(record)
console.log('Column: ' + column.dataIndex);
console.log('was just ' + state)
}
如果没有活动编辑器,那么myGrid.editingPlugin.getActiveEditor().field
将抛出一个错误,这就是为什么我在它周围包装了一个条件
还有一点我应该指出,对于编辑器网格中的验证,我发现在网格列的编辑器定义中放置验证程序配置是最简单的。这将在用户设置字段值时为您提供所有方便的验证CSS,并在用户尝试之前提醒他值是否有问题为了拯救它
要了解我的意思,请尝试在编辑器单元格上的.Mouse的date列中输入字母,您将得到错误消息
编辑
看来我误解了你原来的问题,不过我会把我对你上面问题的回答分解一下
问题1
一旦您完成编辑(单击ENTER
or),您对mygridStore.getModifiedRecords()
的调用应该可以正常工作,因为该记录将被提交到存储区。我看到它不起作用,我将稍后介绍
我应该指出,ExtJS4有一个store.sync()
方法
您可以调用这个sync
方法,它将为您处理所有这些操作,而不是从存储中提取修改过的记录、对它们进行编码、手动执行ajax请求以将它们保存到服务器,然后手动提交它们
如果您有不同的URL来处理商店的load
和sync
方法触发的不同创建、读取、更新和销毁操作,您可以使用商店的代理api
config将URL映射到所述的这些操作。或者您可以设置服务器端控制器以区分在商店的加载
请求(读取操作默认为HTTP GET)和同步请求(创建、更新和删除操作默认为HTTP POST)之间
在服务器端可以有许多不同的方法来实现这一点,我通常的做法是为任何给定的存储区提供一个用于GET请求的SQL存储过程和一个用于POST请求的SQL存储过程。我将存储区名称作为一个额外的参数,然后我的服务器端控制器根据它是否为GET运行相应的存储过程或者一个帖子请求
问题2
单元格编辑不支持checkcolumn
编辑。您必须使用不同的处理程序来侦听更改,如下所示:
Ext.define('MyApp.controller.MyController', {
init: function() {
this.control({
'mygridpanel': {
validateedit: function(plugin, edit) {
// silly validation function
if (edit.value != 'A Valid Value') {
return false;
}
},
},
});
},
});
// myGrid is a reference to your Ext.grid.Panel instance
if (myGrid.editingPlugin.editing) {
var value = myGrid.editingPlugin.getActiveEditor().field.value
console.log('value: ' + value);
}
checkchange: function (column, rowIndex, checked) {
var record = store.getAt(rowIndex),
state = checked ? 'checked' : 'unchecked'
console.log('The record:');
console.log(record)
console.log('Column: ' + column.dataIndex);
console.log('was just ' + state)
}
您对mygridStore.getModifiedRecords()
的调用也应该能够获取检查更改,但是,它们在被检查后会立即提交到网格存储。store.sync()
还将获取对checkcolumn的更改
问题3
我不能完全说出是什么导致了这个问题,但您的validatedit
事件可能有点奇怪,您的处理程序应该返回true或false
正如我之前所说,我误解了你最初提出这个问题的原因。我以为你在编辑过程中试图进行某种验证。现在我明白了