PDA

View Full Version : RowEditor and update



pezze
11 Aug 2009, 4:30 AM
I'm trying to update record in a GridPanel using RowEditor extension and DirectStore. Unfortunatelly my store only pass id to my page, so I cannot update.

If I listen to afteredit event I can see all the fields.

Can you help me?

Here it is my code:


var inhabitansRecipient = new Ext.data.DirectStore({
//directFn: Inhabitants.read,
api: {
read: Inhabitants.Read,
update: Inhabitants.Update
},
autoSave: true,
remoteSort: false,
autoLoad: false,
reader: new Ext.data.JsonReader({
idProperty: 'id',
root: 'data',
paramsAsHash: true,
fields: Ext.data.Record.create([
{name: 'id', type: 'int'},
{name: 'idcondominio', type: 'int'},
{name: 'nome', type: 'string'},
{name: 'cognome', type: 'string'},
{name: 'azienda', type: 'string'},
{name: 'indirizzo', type: 'string'},
{name: 'comune', type: 'string'},
{name: 'cap', type: 'string'},
{name: 'provincia', type: 'string'},
{name: 'codicefiscale', type: 'string'},
{name: 'partitaiva', type: 'string'},
{name: 'telefonocellulare', type: 'string'},
{name: 'telefonofisso', type: 'string'}
])
}),
writer: new Ext.data.JsonWriter({
encode: false,
writeAllFields: true // write all fields, not just those that changed
})
});

var inhabitansColModel = new Ext.grid.ColumnModel([
{dataIndex: 'id', id:'id', sortable: false, hidden: true},
{dataIndex: 'idcondominio', sortable: false, hidden: true},
{dataIndex: 'cognome', header: "Cognome", sortable: true, hidden: false, editor: { xtype: 'textfield', allowBlank: true}},
{dataIndex: 'nome', header: "Nome", sortable: true, hidden: false, editor: { xtype: 'textfield', allowBlank: true} },
{dataIndex: 'azienda', header: "Azienda", sortable: true, hidden: false, editor: { xtype: 'textfield', allowBlank: true}},
{dataIndex: 'indirizzo', header: "Indirizzo", sortable: true, hidden: false, editor: { xtype: 'textfield', allowBlank: true}},
{dataIndex: 'comune', header: "comune", sortable: true, hidden: false, editor: { xtype: 'textfield', allowBlank: true}},
{dataIndex: 'cap', header: "cap", sortable: true, hidden: false, editor: { xtype: 'textfield', allowBlank: true}},
{dataIndex: 'provincia', header: "provincia", sortable: true, hidden: false, editor: { xtype: 'textfield', allowBlank: true}},
{dataIndex: 'codicefiscale', header: "codicefiscale", sortable: true, hidden: false, editor: { xtype: 'textfield', allowBlank: true}},
{dataIndex: 'partitaiva', header: "partitaiva", sortable: true, hidden: false, editor: { xtype: 'textfield', allowBlank: true}},
{dataIndex: 'telefonocellulare', header: "telefonocellulare", sortable: true, hidden: false, editor: { xtype: 'textfield', allowBlank: true}},
{dataIndex: 'telefonofisso', header: "telefonofisso", sortable: true, hidden: false, editor: { xtype: 'textfield', allowBlank: true}}
]);

var inhabitansEditor = new Ext.ux.grid.RowEditor({
saveText: 'Aggiorna',
cancelText: 'Annulla'
});

var inhabitansGrid = new Ext.grid.GridPanel({
loadMask: true,
colModel: inhabitansColModel,
hidden: false,
layout:'fit',
emptyText: '<br/><div align=\"center\">Nessun abitante caricato</div><br/>',
stripeRows: true,
//autoExpandColumn: true,
store: inhabitansRecipient,
plugins: [inhabitansEditor]
});


And this is the post:

{"action":"Inhabitants","method":"Update","data":[3],"type":"rpc","tid":3}

Thanks

galdaka
11 Aug 2009, 4:52 AM
Please, post this thread in "Help forum".

Greetings,

pezze
11 Aug 2009, 7:11 AM
An update.

I'm using ExtDirect .NET version.

If I create a DirectMethod in .NET with all:


[DirectMethod]
public JsonResult Update(Int64 id,
Int64 idcondominio,
string nome,
string cognome,
string azienda,
string indirizzo,
string comune,
string cap,
string provincia,
string codicefiscale,
string partitaiva,
string telefonocellulare,
string telefonofisso)
{
return new JsonResult(false);
}


I got this error:

too much recursion

Artistan
22 Sep 2009, 11:05 AM
I am having the same problem with the ID passing to the update method, but no actual data.

This is the post to my direct router.

{"action":"mod_Company_Inventory","method":"update_prefs","data":["[\"3\"]"],"type":"rpc","tid":3}

Here is my Grid with DirectStore and RowEditor...


/*!
* Ext JS Library 3.0+
* Copyright(c) 2006-2009 Ext JS, LLC
* [email protected]
* http://www.extjs.com/license
*/
Ext.onReady(function() {


try{
var p = new Ext.Panel({
title: 'Remote Call Log',
//frame:true,
width: 900,
height: 400,
layout:'fit',

items: [{
xtype: 'grid',
stripeRows: true,
viewConfig: {
forceFit: true,
markDirty: false
},
autoHeight: true,
plugins: [
new Ext.ux.grid.RowEditor({
saveText: 'Update'
})
],
store: {
xtype: 'directstore',
autoDestroy: true,
autoLoad: true,
autoSave: true,
remoteSort: false,

api: {
read : Ext.bb.mod_Company_Inventory.get_prefs,
create : Ext.bb.mod_Company_Inventory.new_pref,
update : Ext.bb.mod_Company_Inventory.update_prefs,
destroy : Ext.bb.mod_Company_Inventory.remove_prefs
},
totalProperty: 'totalCount',
root: 'items',
paramOrder: ['compid'],
baseParams: {compid:'37'},
paramsAsHash:false,
idProperty: 'up_id',
fields: [
{name: 'up_id', type: 'int'},
{name: 'compid',type: 'int'},
{name: 'email'},
{name: 'site',type: 'int'},
{name: 'login'},
{name: 'status',type: 'int'},
{name: 'manual_upload',type: 'int'},
{name: 'defaultqty',type: 'int'},
{name: 'defaultcond'},
{name: 'auto',type: 'int'},
{name: 'last_status',type: 'int'},
{name: 'last_date', type: 'date', dateFormat: 'Y-m-d h:i:s'}
],
writer: new Ext.data.JsonWriter({
encode: true,
writeAllFields: true,
listful:true
})

},
columns: [
{
header: 'Id',
sortable: true,
dataIndex: 'up_id'
},
{
header: 'Login',
sortable: true,
dataIndex: 'login',
editor: {
xtype: 'textfield',
allowBlank: false
}
},
{
header: 'Email',
sortable: true,
dataIndex: 'email',
editor: {
xtype: 'textfield',
allowBlank: false
}
},
{
header: 'site',
sortable: true,
dataIndex: 'site',
editor: {
xtype: 'textfield',
allowBlank: false
}
},
{
header: 'Status',
sortable: true,
dataIndex: 'status',
editor: {
xtype: 'textfield',
allowBlank: false
}
},
{
header: 'manual_upload',
sortable: true,
dataIndex: 'manual_upload',
editor: {
xtype: 'textfield',
allowBlank: false
}
},
{
header: 'defaultqty',
sortable: true,
dataIndex: 'defaultqty',
editor: {
xtype: 'textfield',
allowBlank: true
}
},
{
header: 'defaultcond',
sortable: true,
dataIndex: 'defaultcond',
editor: {
xtype: 'textfield',
allowBlank: true
}
},
{
header: 'auto',
sortable: true,
dataIndex: 'auto',
editor: {
xtype: 'textfield',
allowBlank: false
}
},
{
header: 'last_status',
sortable: true,
dataIndex: 'last_status',
editor: {
xtype: 'textfield',
allowBlank: true
}
},
{
header: 'Last Upload',
sortable: true,
renderer: Ext.util.Format.dateRenderer('Y-m-d h:i:s'),
dataIndex: 'last_date',
editor: {
xtype: 'datefield',
minValue: '01/01/2009',
minText: 'Jan 1st 2009 is the minimum value!',
maxValue: (new Date()).format('m/d/Y'),
allowBlank: true
}
},
]
}]
}).render(Ext.getBody());

} catch (e) {
console.log(e);
}
});


Help would be appreciated!!

Artistan
22 Sep 2009, 11:14 AM
When I leave out the

idProperty: 'up_id',
I get a more expected post...

{"action":"mod_Company_Inventory","method":"new_pref","data":[[{"up_id":4,"compid":37,"email":"[email protected]","site":1,"login":"jmiller","status":"1","manual_upload":0,"defaultqty":"","defaultcond":"REF","auto":1,"last_status":"","last_date":"","id":"ext-record-138"}]],"type":"rpc","tid":3}
but this is submited to the create function because there is no ID!

Thanks for any feedback!!!

Artistan
22 Sep 2009, 1:22 PM
After tracking the DirectStore update through h3ll and back again....


Ext.data.JsonWriter....

/**
* Final action of a write event. Apply the written data-object to params.
* @param {String} action [Ext.data.Api.actions.create|read|update|destroy]
* @param {Record[]} rs
* @param {Object} http params
* @param {Object} data object populated according to DataReader meta-data "root" and "idProperty"
*/
render : function(action, rs, params, data) {
Ext.apply(params, data);

if (this.encode === true) { // <-- @deprecated returnJson
if (Ext.isArray(rs) && data[this.meta.idProperty]) {
params[this.meta.idProperty] = Ext.encode(params[this.meta.idProperty]);
}
params[this.meta.root] = Ext.encode(params[this.meta.root]);
}
},


Note that the JsonWriter adds a second parameter to return (ids) if the idProperty is setup correctly. ("valid")

I ended my search when I found that the it ends up in the doCall method with....


m.len // this is the length of arguments for your directstore function!


Finally realizing that the Update function needs to accept 2 parameters (ids & data) otherwise it will never work with idProperty set.

Not sure where this (is|should|will be) documented.
Hope this helps someone else out!

Artistan
22 Sep 2009, 1:39 PM
I would like to suggest that the idProperty would check the m.len (method arguments length) for (m.len==2) and throw an exception or something if not. I took me quite awhile to find the solution (correct procedure) for this. A simple check would help!
Thanks.