PDA

View Full Version : Row Editor with CRUD generates create instead of update...



The Transporter
19 Feb 2010, 8:31 AM
Hello all,

I'm using for the first time a RowEditor in my stuff and I'm having a problem.
Overall, it seems to work good but everytime I update a row, it generate a Create request instead of an Update.

You can check the code of my Gridpanel here (It's a module for a desktop).



MyDesktop.adsListingWindow = Ext.extend(Ext.app.Module, {
init : function(){
this.launcher = {
text: 'Ads Listing',
iconCls: 'icon-application_view_list',
handler : this.createWindow,
scope: this,
windowId:windowIndex
}

},

createWindow : function(src){

var desktop = this.app.getDesktop();

var adsStore = new Ext.data.Store({
id: 'adsStore',
autoDestroy: true,
autoLoad: {params:{start:0, limit:100}},
remoteSort: true,
sortInfo: {
field: 'COMPANY_NAME',
direction: 'ASC'
},
proxy: new Ext.data.HttpProxy({
api: {
read: '_ajax/ads.php?a=r',
create: '_ajax/ads.php?a=c',
update: '_ajax/ads.php?a=u',
destroy: '_ajax/ads.php?a=d'
}
}),
writer: new Ext.data.JsonWriter({
encode: true
//writeAllFields: true
}),
reader: new Ext.data.JsonReader({
root: 'results',
totalProperty: 'totalCount',
fields: [{
name: 'ID',
type: 'string',
mapping: 'ID'
},
{
name: 'PARENT_ID',
type: 'string',
mapping: 'PARENT_ID'
},
{
name: 'WHAT',
type: 'string',
mapping: 'WHAT'
},
{
name: 'WHERE_LOC',
type: 'string',
mapping: 'WHERE_LOC'
},
{
name: 'COMPANY_NAME',
type: 'string',
mapping: 'COMPANY_NAME'
},
{
name: 'ADDRESS',
type: 'string',
mapping: 'ADDRESS'
},
{
name: 'region',
type: 'string',
mapping: 'region'
},
{
name: 'country',
type: 'string',
mapping: 'country'
},
{
name: 'WEB',
type: 'string',
mapping: 'WEB'
},
{
name: 'EMAIL',
type: 'string',
mapping: 'EMAIL'
},
{
name: 'CATEGORY',
type: 'string',
mapping: 'CATEGORY'
},
{
name: 'PHONE',
type: 'string',
mapping: 'PHONE'
},
{
name: 'FAX',
type: 'string',
mapping: 'FAX'
},
{
name: 'uniqidrow',
type: 'string',
mapping: 'uniqidrow'
},
{
name: 'same_company_id',
type: 'string',
mapping: 'same_company_id'
}]
})
});

var filters = new Ext.ux.grid.GridFilters({
// encode and local configuration options defined previously for easier reuse
encode: true, // json encode the filter query
local: false, // defaults to false (remote filtering)
filters: [{
type: 'string',
dataIndex: 'COMPANY_NAME'
}, {
type: 'list',
dataIndex: 'region',
options: ['Bruxelles','Hainaut','Luxembourg','Wallonnie','Liege','Namur'],
phpMode: true
}, {
type: 'list',
dataIndex: 'country',
options: ['Belgique'],
phpMode: true
}, {
type: 'string',
dataIndex: 'PHONE'
}, {
type: 'string',
dataIndex: 'FAX'
}]
});

var editor = new Ext.ux.grid.RowEditor({
saveText: 'Update'
});

var grid = new Ext.grid.GridPanel({
store: adsStore,
columns: [
//{header: 'id', width: 160, sortable: true, dataIndex: 'ID'},
{header: 'Company', width: 100, sortable: true, dataIndex: 'COMPANY_NAME',id:'company',editor:{xtype:'textfield',allowBlank:false}},
{header: 'Region',
width: 60,
sortable: true,
dataIndex: 'region',
editor:{
xtype:'combo',
mode: 'local',
typeAhead: true,
triggerAction: 'all',
lazyRender: true,
store: new Ext.data.SimpleStore({
fields: ['name'],
data: [['Bruxelles'],['Hainaut'],['Luxembourg'],['Wallonnie'],['Liege'],['Namur']]
}),
displayField: 'name',
valueField: 'name'
}
},
{header: 'Country', width: 60, sortable: true, dataIndex: 'country'},
{header: 'Phone', width: 80, sortable: true, dataIndex: 'PHONE',editor:{xtype:'textfield',allowBlank:true}},
{header: 'Fax', width: 100, sortable: true, dataIndex: 'FAX',editor:{xtype:'textfield',allowBlank:true}}
],
stripeRows: true,
region: 'center',
autoExpandColumn: 'company',
loadMask: true,
stateful: true,
stateId: 'grid',
plugins: [filters,editor],
bbar: [new Ext.PagingToolbar({
store: adsStore,
pageSize:100,
plugins: [filters],
displayInfo:true
}),'->',{
text: 'Clear Filter Data',
handler: function () {
filters.clearFilters();
}
}],
view: new Ext.ux.grid.BufferView({
scrollDelay: false
}),
listeners: {
celldblclick: function (sm, ridx, cidx, e) {

}
}

});

var win = desktop.getWindow('adsListingWindow');
if(!win){
win = desktop.createWindow({
id: 'adsListingWindow',
title:src.text,
width:640,
height:480,
iconCls: 'icon-application_view_list',
shim:false,
animCollapse:false,
constrainHeader:true,
items: [grid],
layout: 'border'
});
}

win.show();
}
});


Thanks for the help.

Heathro
19 Mar 2010, 11:17 AM
I was having this issue as well and stumbled across the following tutorial for ColdFusion and the Editor Grid: http://www.coldfusion-ria.com/Blog/index.cfm/2009/12/14/ExtJS-30-Editor-Grid-with-ColdFusion.

Try specifying which field is your primary key by adding


idProperty: 'ID'

to your reader configuration. Full details are in the url above right at the end of the examples (before the comments).

Pachat
24 Jun 2010, 2:32 AM
Be aware, that if you add an id property to the reader itself, you will end with the same problem :


var reader_projects = new Ext.data.JsonReader({
id: 'id-reader_projects', //do'nt put an id : it leads to a create xaction instead of update
root: 'rows',
idProperty: 'id',
successProperty: 'success',
fields: record_projects
});