PDA

View Full Version : How to post a store.data as a request parameter ?



mozexty
14 Jun 2010, 11:57 AM
Hi,
I would like to use the dirty (modified) records of my GridPanel as a parameter of an Ext.Ajax.request.
I think the store might be the place to get those records. So i did this with no success:




Ext.Ajax.request({
method : 'POST',
waitMsg:'Saving...',
url : 'save_bt.php',
params : {
first : txaAnomConst.getValue(),
second : txaConstEssais.getValue(),
third : stoMyStore.data
},
success : function(){}
});

I've also tried to encode it doing third : Ext.encode(stoMyStore.data) but i've got a "too much recursion" error in FireBug.
Is there anyway to do this?

CrazyEnigma
14 Jun 2010, 6:16 PM
First of all, I wouldn't call "data". I am not too sure if this is even available. data is used in the config, but I don't see it as a public property. Although, it may look like a config property, it might get destroyed. It may not even be set if you are calling a URL to obtain the data. I would think to use getModifiedRecords(), as this returns an array. But I also think that you can manage your records using CRUD or the save() method on the store.

Animal
14 Jun 2010, 9:45 PM
The easy way is to cofigure your Store with an api (See docs), and call save() on it. That will post modified Records.

mozexty
15 Jun 2010, 7:00 AM
The easy way is to cofigure your Store with an api (See docs), and call save() on it. That will post modified Records.

I don't want to submit only the store data, but it will be a request parameter among others.
I'll try the getModifiedRecords() solution and let you know.
Thanks for the answer.

Mike Robinson
15 Jun 2010, 7:10 AM
Well, as you know, "the parameters to an AJAX request" are simply a JavaScript object (a "hash," to an old Perl-hound like me). And, so are any of the records in a Store.

The one thing that you should remember, however ... and this one bit me recently, as some of you may recall ... is that when you pass a structure around you're probably passing a reference to it. You therefore might want to make a "shallow copy of" the data, and pass that.

For instance:


Ext.Ajax.request({ ...
params: { rec: Ext.apply({}, store.getAt(0)) ... }
});

Caution: extemporaneous coding... do not try this at home.

The idea here is that using "Ext.apply" in this way, against an empty-hash, is that it will make a shallow-copy of the record returned by the store. This record becomes the (I pulled this word out of my hat) "rec" parameter of the Ajax request.

Do you "have to" do this? I dunno; I just do.

Animal
15 Jun 2010, 7:18 AM
I don't want to submit only the store data, but it will be a request parameter among others.
I'll try the getModifiedRecords() solution and let you know.
Thanks for the answer.

Still easier to do



myStore.baseParams = {
extraParam: 'value',
...
};
myStore.save();

mozexty
16 Jun 2010, 10:54 AM
The solution of Animal did it, but partially. To make things clearer, i'd like to show you my user interface.20968
1- I have a lot of textfields/timefield/datefield ... which i'd like to submit. No problem at this stage.
2- I want to get the mysql auto-generated Id (primary key) of the previous submit.
3- I want to use the previous Id as an external key to send each of the grids.

That's why the title of my post is "How to post a store.data as a request parameter". So that i could send the grid1 and grid2's data as parameters of the first submit (Point 1) and do points 2 and 3 on the server side, which is easier for me.

I hope it's clearer

Animal
16 Jun 2010, 11:54 AM
OH. MY. GOD!

WHAT is that?

Panels, Panels everywhere? WHY???

Never glanced at labelAlign: 'top'?

OK, if you really just want to send the whole grid's data, then iterate through the Records in the Store, create an Array of their data properties, serialize into JSON and submit that. Decode the JSON using a JSON library on the server.

mozexty
17 Jun 2010, 10:47 AM
Yes, Panels,
my UI needs to look like the paper form that we are using at present. It was a requirement.

I will iterate through the Records.
Thanks, thanks, thanks....