PDA

View Full Version : Updated value of baseParams is NOT SENT to server



mark_romeo87
2 Nov 2009, 10:19 PM
How can I update the value dynamically of a variable in baseParams so that it can send it to server correctly?

the text in red is the part of the code that I THINK would do the functionality that I want, but it seems it wont do the trick:



var remoteJsonStore = new Ext.data.JsonStore({
proxy: remoteProxy,
storeId: 'ourRemoteStore',
root: 'records',
baseParams: {
"debug": 1,
"oprtn": ""
},
autoLoad: false,
totalProperty: 'totalCount',
remoteSort: true,
fields: recordFields,
idProperty: 'id',
successProperty: 'success',
writer: writer,
autoSave: false,
listeners: {
exception: function (proxy, type, action, o, response, args) {
switch (action) {
case "update":
//this.setBaseParam({oprtn:"update"});
this.baseParams.oprtn = "update";
alert(this.baseParams.oprtn);
break;
case "create":
alert("create");
break;
case "destroy":
this.baseParams.oprtn = "delete";
break;
default:
alert("read");
}
}
}
});


http://a.imagehost.org/0662/ScreenShot003.jpg (http://a.imagehost.org/view/0662/ScreenShot003)

Heres the server response in firebug

http://a.imagehost.org/t/0307/extjs_datawriter_01.jpg (http://a.imagehost.org/view/0307/extjs_datawriter_01)

While here is the code for my grid



Ext.onReady(function () {
Ext.BLANK_IMAGE_URL = '../../lib/extjs/resources/images/default/s.gif';
Ext.QuickTips.init();

var remoteProxy = new Ext.data.HttpProxy({
api: {
read: 'dataQuery.php?oprtn=r',
create: 'dataCreate.php',
update: 'dataUpdate.php',
destroy: 'dataDelete.php'
}
});

var recordFields = [{
name: 'id',
mapping: 'id'
},
{
name: 'firstname',
mapping: 'firstname'
},
{
name: 'lastname',
mapping: 'lastname'
},
{
name: 'street',
mapping: 'street'
},
{
name: 'city',
mapping: 'city'
},
{
name: 'state',
mapping: 'state'
},
{
name: 'zipcode',
mapping: 'zip'
}];

var writer = new Ext.data.JsonWriter({
encode: true,
writeAllFields: false
});

var remoteJsonStore = new Ext.data.JsonStore({
proxy: remoteProxy,
storeId: 'ourRemoteStore',
root: 'records',
baseParams: {
"debug": 1,
"oprtn": ""
},
autoLoad: false,
totalProperty: 'totalCount',
remoteSort: true,
fields: recordFields,
idProperty: 'id',
successProperty: 'success',
writer: writer,
autoSave: false,
listeners: {
exception: function (proxy, type, action, o, response, args) {
switch (action) {
case "update":
//this.setBaseParam({oprtn:"update"});
this.baseParams.oprtn = "update";
alert(this.baseParams.oprtn);
break;
case "create":
alert("create");
break;
case "destroy":
this.baseParams.oprtn = "delete";
break;
default:
alert("read");
}
}
}
});

var grid = {
xtype: 'editorgrid',
columns: columnModel,
id: 'myEditorGrid',
store: remoteJsonStore,
trackMouseOver: true,
loadMask: true,
bbar: pagingToolbar,
stripeRows: true,
forceValidation: false,
viewConfig: {
forceFit: true
},
listeners: {
cellcontextmenu: doCellCtxMenu,
destroy: function (thisGrid) {
if (thisGrid.rowCtxMenu) {
thisGrid.rowCtxMenu.destroy();
}
}
}

}

new Ext.Window({
height: 350,
width: 550,
border: false,
layout: 'fit',
items: grid
}).show();

remoteJsonStore.load({
params: {
start: 0,
limit: 50
}
});

}); // eof onReady func


Heres the thing, whenever I do an Update in the grid then I click the Save Changes button, I want the initial value of baseParams.oprtn="" to be updated to baseParams.oprtn="update", so that i can do the right operation on the server side. Same thing to deleting a record and inserting, so the baseParams.oprtn would be "destroy" or "create".

I dont know if the "exception" in my remoteJsonStore is the RIGHT APPROACH to it. Please anyone help me on this, i cant sleep nor eat right anymore.:((


-Mark from the Philippines

tryanDLS
3 Nov 2009, 1:42 PM
Please don't post the same thread just because you don't see it immediately - post moderation is on.

mark_romeo87
4 Nov 2009, 5:33 AM
sorry tryanDLS, since this is my first post, I overlooked the message after I submitted my 1st post (just saw it after my 2nd post), It wont happen again:).

carol.ext
4 Nov 2009, 7:19 AM
Heres the thing, whenever I do an Update in the grid then I click the Save Changes button, I want the initial value of baseParams.oprtn="" to be updated to baseParams.oprtn="update"

But the code you highlighted in red is inside the exception listener. Where is your Save Changes button?

mark_romeo87
13 Nov 2009, 9:57 AM
Hello Carol, oh I almost forgot this thread,

yep your right, why did I put the code INSIDE THE EXCEPTION LISTENER,:D
I thought "exception listener" is an event that is always invoked whenever theres
a Delete, Create, Update, Read, in the store.
Then I review my English diction, then read Ext Manual, read again the book Ext in Action then read searched here in the forum
then I do this:


listeners: {
beforeload: function (s, o) {
remoteJsonStore.setBaseParam('oprtn', 'read');
},
beforewrite: function (hp, a, rs, o) {
switch (a) {
case "update":
remoteJsonStore.setBaseParam('oprtn', 'update');
break;
case "create":
remoteJsonStore.setBaseParam('oprtn', 'create');
break;
case "destroy":
remoteJsonStore.setBaseParam('oprtn', 'destroy');
break;
default:
remoteJsonStore.setBaseParam('oprtn', 'read');
}
}
...........



I do this just to tell the server that I am doing delete or create or etc. and do some query,
And realized that my approach is wrong because Ext Data.Writer is already telling the server through the variable xaction.
Just learning this great library for a week, sorry for my lame question. thanks for reading:)