Ext JS 3.4:用于单元格编辑的事件监听器
Ext JS 3.4 : Event listener for cell editing
我在 Ext Js 3.4
中遇到使用单元格编辑器触发编辑事件的问题。
我正在尝试实现在按下 'Enter'
后对编辑的单元格触发 ajax 调用。
目前,我只是替换为 console.log('hi')
,但在我按下 'Enter'
后它没有显示任何内容。
我不确定我的代码有什么问题。感谢有人能指出来。谢谢。
var grid = new Ext.grid.EditorGridPanel({
store: api_store,
loadMask: true,
clicksToEdit: 1,
tbar: [{
text: 'Create',
handler: function () { }
}],
columns: [
{
id: 'name',
header: 'Key Name',
width: 300,
sortable: true,
dataIndex: 'name',
editor: {
xtype: 'textfield',
allowBlank: false,
listener: {
edit: function (el) {
console.log('hi');
}
}
}
},
{
header: 'Key Value',
width: 500,
sortable: false,
dataIndex: 'key'
}
],
sm: new Ext.grid.RowSelectionModel({ singleSelect: true }),
viewConfig: {
forceFit: true
},
height: 210,
stripeRows: true,
height: 350,
title: 'Keys'
});
解法:
使用 EditorGridPanel afteredit
事件:
afteredit(e)
Fires after a cell is edited. The edit event object has the following
properties
- grid - This grid
- record - The record being edited
- field - The field name being edited
- value - The value being set
- originalValue - The original value for the field, before the edit.
- row - The grid row index
- column - The grid column index
Parameters:
e : Object An edit event (see above for description)
示例:
Ext.onReady(function () {
var api_store = new Ext.data.ArrayStore({
fields: ['key', 'name'],
data: [
['1', 'Name1'],
['2', 'Name2'],
['3', 'Name3']
]
});
var grid = new Ext.grid.EditorGridPanel({
renderTo: Ext.getBody(),
store: api_store,
loadMask: true,
clicksToEdit: 1,
tbar: [{
text: 'Create',
handler: function () { }
}],
listeners: {
afteredit: function(e) {
console.log('After edit. Column: ' + e.field);
}
},
columns: [
{
id: 'name',
header: 'Key Name',
width: 300,
sortable: true,
dataIndex: 'name',
editor: {
xtype: 'textfield',
allowBlank: false
}
},
{
header: 'Key Value',
width: 500,
sortable: false,
dataIndex: 'key'
}
],
sm: new Ext.grid.RowSelectionModel({ singleSelect: true }),
viewConfig: {
forceFit: true
},
height: 210,
stripeRows: true,
height: 350,
title: 'Keys'
});
});
我在 Ext Js 3.4
中遇到使用单元格编辑器触发编辑事件的问题。
我正在尝试实现在按下 'Enter'
后对编辑的单元格触发 ajax 调用。
目前,我只是替换为 console.log('hi')
,但在我按下 'Enter'
后它没有显示任何内容。
我不确定我的代码有什么问题。感谢有人能指出来。谢谢。
var grid = new Ext.grid.EditorGridPanel({
store: api_store,
loadMask: true,
clicksToEdit: 1,
tbar: [{
text: 'Create',
handler: function () { }
}],
columns: [
{
id: 'name',
header: 'Key Name',
width: 300,
sortable: true,
dataIndex: 'name',
editor: {
xtype: 'textfield',
allowBlank: false,
listener: {
edit: function (el) {
console.log('hi');
}
}
}
},
{
header: 'Key Value',
width: 500,
sortable: false,
dataIndex: 'key'
}
],
sm: new Ext.grid.RowSelectionModel({ singleSelect: true }),
viewConfig: {
forceFit: true
},
height: 210,
stripeRows: true,
height: 350,
title: 'Keys'
});
解法:
使用 EditorGridPanel afteredit
事件:
afteredit(e)
Fires after a cell is edited. The edit event object has the following properties
- grid - This grid
- record - The record being edited
- field - The field name being edited
- value - The value being set
- originalValue - The original value for the field, before the edit.
- row - The grid row index
- column - The grid column index
Parameters:
e : Object An edit event (see above for description)
示例:
Ext.onReady(function () {
var api_store = new Ext.data.ArrayStore({
fields: ['key', 'name'],
data: [
['1', 'Name1'],
['2', 'Name2'],
['3', 'Name3']
]
});
var grid = new Ext.grid.EditorGridPanel({
renderTo: Ext.getBody(),
store: api_store,
loadMask: true,
clicksToEdit: 1,
tbar: [{
text: 'Create',
handler: function () { }
}],
listeners: {
afteredit: function(e) {
console.log('After edit. Column: ' + e.field);
}
},
columns: [
{
id: 'name',
header: 'Key Name',
width: 300,
sortable: true,
dataIndex: 'name',
editor: {
xtype: 'textfield',
allowBlank: false
}
},
{
header: 'Key Value',
width: 500,
sortable: false,
dataIndex: 'key'
}
],
sm: new Ext.grid.RowSelectionModel({ singleSelect: true }),
viewConfig: {
forceFit: true
},
height: 210,
stripeRows: true,
height: 350,
title: 'Keys'
});
});