Ext中动态修改grid内容


对于Ext.grid.Panel,在这里不做过多介绍,直面主题,在Ext.grid.Panel的基础上怎样修改成动态列表。

一、首先要定义一下可编辑列:

var cellEditPlugin = Ext.create('Ext.grid.plugin.CellEditing', {
clicksToEdit: 2
});

其中clicksToEdit=1,是单击修改;clicksToEdit=2,是双击修改

二、在Ext.grid.Panel定义中加入plugins: [cellEditPlugin]

var test= Ext.create('Ext.grid.Panel', {
title : 'test',
frame : true,
store : rptEb5sStore,
plugins: [cellEditPlugin]

三、在grid的列中加入editor:{xtype:'textarea'},这样,grid列就可编辑了,textarea是文本框

{
header : 'test',
dataIndex : 'test',
menuDisabled : true,
draggable : false,
editor:{xtype:'textarea'}
}

四、保存到数据库中,我们需要监听,此行数据,因为change事件中,我们无法获得行号,我就多写了一个click,需要声明一个全局变量:hh,整体代码如下:

{
header : 'test',
dataIndex : 'test',
menuDisabled : true,
draggable : false
listeners : {
click : function(field, resource, rowIndex) {
hh=rowIndex;
}
},
editor:{xtype:'textarea',listeners : {
change : function(field, newValue, oldValue) {
var id = Grid.getStore().getAt(hh).id
Ext.Ajax.request({
url : basePath + '/test/test/update.do',
params : {
id : id,
bgyy : newValue
},
success : function(response) {
unMask();
var result = Ext.decode(response.responseText);
if (result.success) {
Ext.Msg.alert('操作提示', '修改成功', function() {
xlGdStore.reload();
});
} else {
Ext.Msg.alert('操作提示', result.msgText);
}
}
});
}
}}
}

五、还有一种直接监测列表行选中的方式:

Grid.on('select', function (grid, record, rowIndex, e) {
alert('213');
});


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM