PDA

View Full Version : RowEditing plugin with REST proxy in store is not sending the whole record



deroude
12 Sep 2013, 4:58 PM
This is my model:


Ext.define('MyApp.model.Connection', { extend: 'Ext.data.Model',
fields: [{name: 'id', defaultValue: -1}, 'name', 'url', 'type']
});

This is my store:

Ext.define('MyApp.store.Connection', {
extend: 'Ext.data.Store',
requires: 'AdminGUI.model.Connection',
model: 'AdminGUI.model.Connection',
// autoLoad: true,
autoSync: true,
autoDestroy: true,

proxy: {
type: 'rest',
reader: {
type: 'json',
root: 'data'
},
writer: {
type: 'json',
writeAllFields: true
}
},
listeners: {
write: function(store, op) {
console.log(op); //writes name,url,type, but NOT id
}
}
});

This is my grid:

Ext.define('MyApp.view.DBConnectionGrid', {
extend: 'Ext.grid.Panel',
alias: 'widget.dbconnectiongrid',
requires: ['MyApp.model.Connection'],
title: 'DB Connections',
initComponent: function() {
this.columns = [
{
dataIndex: 'id',
text: 'ID',
sortable: true,
hidden: true
},
{
dataIndex: 'name',
text: 'Name',
flex: 1,
groupable: false,
editor: {xtype: 'textfield'}
},
{
dataIndex: 'type',
text: 'Type',
flex: 1,
editor: {
xtype: 'combobox',
store: Ext.create('MyApp.store.ConnectionTypeSelector'),
editable: false,
autoSelect: true,
displayField: 'display',
valueField: 'value'
}
},
{
dataIndex: 'url',
text: 'Url',
flex: 2,
editor: {xtype: 'textfield'}
}
];
this.store = Ext.create('MyApp.store.Connection');
this.store.getProxy().url = 'DBConnectionREST/' + this.serviceId;
this.store.load();
this.callParent();
},
plugins: [Ext.create('Ext.grid.plugin.RowEditing', {
pluginId: 'connectionEdit',
listeners: {
cancelEdit: function(rowEditing, context) {
// Canceling editing of a locally added, unsaved record: remove it
if (context.record.phantom) {
context.store.remove(context.record);
}
},
edit: function(rowEditing, context, x, y) {
context.record.commit();
}
}})],
tbar: [
{
text: 'Add connection',
iconCls: 'db-add',
handler: function() {
var grid = this.up().up();
grid.getStore().insert(0, new MyApp.model.Connection());
grid.getPlugin('connectionEdit').startEdit(0, 0);
}
},
{
text: 'Delete connection',
iconCls: 'delete',
id: 'connectionDelete',
disabled: true,
handler: function() {
var grid = this.up().up();
var selection = grid.getView().getSelectionModel().getSelection()[0];
if (selection) {
grid.getStore().remove(selection);
}
}
}],
listeners: {
selectionchange: function(selModel, selections) {
this.down('#connectionDelete').setDisabled(selections.length === 0);
}
}
});

slemmon
2 Oct 2013, 10:10 AM
The ID won't be set in the client when the model instance is created. It'll send a create request up to the server and the server will need to set the ID and respond back with the model data including the ID and that will sync in the grid store with that record. Subsequent updates will then send the ID up in the 'update' transactions.