在ExtJS中从GridPanel获取模型
Getting Model from GridPanel in ExtJS
我有一个网格面板,它允许对列进行内联编辑。此列使用组合框作为编辑器,"change"事件和"select"事件都没有为我提供可用于回溯编辑后的值以从网格面板中获取更改后的行的内容。
我相信Ext浮动编辑器的组合框,所以我不能做像这样简单的事情
combo.up()
返回网格。
这是视图中的网格面板:
{
xtype: 'gridpanel',
title: 'Important Projects',
id: 'importantProjectsGrid',
dockedItems: [],
flex: 1,
columns: [
{ header: 'Quote Name', dataIndex: 'QuoteName', flex: 4 },
{ header: 'Quote Status', dataIndex: 'QuoteStatusID', flex: 6, editor: {
xtype: 'combobox',
editable: false,
action: 'QuoteStatus',
selectOnTab: true,
store: 'statuses',
queryMode: 'local',
displayField: 'Description',
valueField: 'Description'
} }
],
store: 'myimpprojects',
selModel: {
selType: 'cellmodel'
},
plugins: [Ext.create('Ext.grid.plugin.CellEditing', {
clicksToEdit: 1
})]
}
以下是与此相关的控制器代码:
init: function () {
this.control({
'[action=QuoteStatus]': {
change: function (combo, new_value, old_value, opts) {
// I need to go back up from this combobox
// to get the row that this value was edited in
// to grab an ID value from that row's data
// in order to make an ajax request
}
}
});
},
谢谢你的帮助!
您可以监视商店的update
事件。
init: function () {
this.getMyimpprojectsStore().on('update', function(store, record) {
// do something with record
});
// ...
},
尝试将侦听器放在CellEditing插件上。beforeedit
、edit
和validateedit
的事件接收一个对象,该对象包含对网格、记录、字段、行和列索引等的引用。您应该能够在事件处理程序中检查组合框,并从中处理您的信息。
文档页面的快速链接:Ext.grid.plugin.CellEditing
我相信更新插件会通过底层存储的api自动处理更新,并在代理为autoSync为true时自动将数据发布到服务器。
配置的代理示例:
Ext.define('MyApp.store.YourStore', {
extend: 'Ext.data.Store',
model: 'MyApp.model.YourGridModel',
autoSync: true, //Commits the changes realtime to the server
proxy: {
type: 'ajax',
batchActions : true, //Commits the changes everytime a value is changed if true o otherwise store the changes and batch update them in 1 single post
api: {
read: 'path/to/select',
create: 'path/to/create',
update: 'path/to/update',
destroy: 'path/to/delete'
},
reader: {
type: 'json',
root: 'results',
successProperty: 'success'
},
writer: {
type: 'json',
writeAllFields: true
},
listeners: {
exception: function(proxy, response, operation){
Ext.MessageBox.show({
title: 'REMOTE EXCEPTION',
msg: operation.getError(),
icon: Ext.MessageBox.ERROR,
buttons: Ext.Msg.OK
});
}
}
},
listeners: {
write: function(proxy, operation){
var response = Ext.JSON.decode(operation.response.responseText);
if(response.success == true)
{
//TODO: Proxy - Messageboxes might be a little anoying we might instead use the status bar in teh grid or something so show status of the operation
Ext.MessageBox.show({
title: this.xFileLibraryTitle,
msg: response.message,
icon: (response.success == true)? Ext.MessageBox.INFO : Ext.MessageBox.ERROR,
buttons: Ext.Msg.OK
});
}
}
}
});
我会特别查找两个配置:"autoSync"answers"batchActions"
希望这能帮助你进一步解决你的问题!
相关文章:
- 如何使用backbone.js从集合中获取模型名称
- Django 使用 JSON 获取模型方法的值
- 在Waterline中动态定义和获取模型
- 在Backbone中通过CID设置和获取模型
- 从Ember视图获取模型属性
- 在不同的模型中获取模型id会在主干中创建表单
- 余烬需要刷新浏览器才能获取模型数据
- Ember.js:使用模型实例的路由获取模型实例的 url 字符串
- 主干视图在模型完成提取后获取模型变量
- 有没有办法轻松获取 C# 模型的 JavaScript 表示形式
- 角度形式 - 从包装器中的字段获取模型
- 如何在获取操作后获取模型属性
- 从 JSON.file 获取模型并将其存储在本地存储主干
- 如何从主干中的嵌套 json 对象获取模型属性
- 在单独的Javascript文件中获取模型值
- 如何获取模型的哪个特定属性已更改?这在Backbone.js中可能吗
- 如何按id从集合中获取模型
- 在ExtJS中从GridPanel获取模型
- 如何获取模型内部的组件引用保存回调函数
- Ember.js渲染模板在其他模板中没有获取模型