PDA

View Full Version : possible to share Storage for a Grid and Form?



Draven
2 Mar 2007, 8:57 AM
I think I have a pretty good handle on the the Grid and Store.js but wondering if it's possible to store both Grid data and Form data in the same storage object.

For example I have a screen where there is a grid along with a Name, Description and a few other fields. Right now I have to make a call for the grid data and the form data seperately, making twice as much code for watching changes to either the grid or the form on the page inorder to fire a save action. It's be nice if I could combine the two and have only one storage to watch and post back for changes. Possible?

It seems that the sote.js in it's present state only supports one set of records, I mean to say a one demensional array of records (I realize it's still a multi-demensional array but it's the best way I can explain it).

It would be nice if you could store data in say ds.data['form_data'] and ds.data['grid_data'] and tell the grid to only monitor/bind to the ds.data['grid_data'] for instances while the form is monitoring/binding to the other. Make sense? This way I only need to make one http query to both retrieve and then later to send back changes, rather than making two and having extra code to monitor both data objects.

If this is already possible then ignore this message and either point me to an example or, if you'd be so kind, give a small example of doing so.

aconran
2 Mar 2007, 11:09 AM
Draven -

It is possible to 'bind' records of a grid to a form field. What you want to do is listen to the rowselection event of the datastore and then update your form accordingly. I have a small snippet of code which I posted here:
http://www.yui-ext.com/forum/viewtopic.php?t=3252

This code goes along with a larger example here:
http://dev.divergingpath.com/playpen/book-alpha.cfm

The plans for auto-data marshalling are currently in the works. (The ability to automatically track the changes from the current datastore to what the user has updated them to).

Aaron

mmcmahon
2 Mar 2007, 11:18 AM
This code goes along with a larger example here:
http://dev.divergingpath.com/playpen/book-alpha.cfm


You had a nice fade-in effect for the content before, when selecting a different row. Did you change that recently?

aconran
2 Mar 2007, 11:33 AM
mmcmahon -

there was an issue with fadeIn in IE7 due to a problem with clearOpacity not being called at the end. I think the code up on my server right now isn't updated. if you are interested more in the problem I was having:
http://www.yui-ext.com/forum/viewtopic.php?t=3105&highlight=clearopacity

I'll try to see if I can update that code this weekend. As well as continue writing the tutorials on building the application.

Aaron

Draven
3 Mar 2007, 6:47 AM
Draven -

It is possible to 'bind' records of a grid to a form field. What you want to do is listen to the rowselection event of the datastore and then update your form accordingly. I have a small snippet of code which I posted here:
http://www.yui-ext.com/forum/viewtopic.php?t=3252

This code goes along with a larger example here:
http://dev.divergingpath.com/playpen/book-alpha.cfm

The plans for auto-data marshalling are currently in the works. (The ability to automatically track the changes from the current datastore to what the user has updated them to).

Aaron

Hi Aaron, thanks for the reply.

Unfortunately I may not have explained myself correctly. The data for the form and the data in the grid are not the same, but are linked together in the database by forigen keys. I want people to be able to edit the grid data and the seperate form data but have all of it stored in the same DS if possible, so I don't have 2 seperate DataStorages I'm watching but just one.

THe reason being is my php calls on the backned make one SQL call to gather all the data and I'd like to keep it that way rather than splitting it into two calls to accomidate two DS's.

Draven
3 Mar 2007, 6:51 AM
As an example, here's what the PHP array looks like before convertig it to json.



array(
'name'=> 'some name',
'desc' => 'some desc..',
'type' => 'some type',
'griddata'=> array('row1'=> array('col1','col2','col3') ...etc...)
);


The griddata key is what needs to go to the grid and the Name, Desc, Type and so on to be bound to the form. What I'm wodering is if this can all be done through one data store or if I must use two seperate ones? I don't think DS supports this kind of multidemensional array storage

aconran
3 Mar 2007, 7:00 AM
Ah, got you. You want to create a master-detail view. When they click a master record in the grid, it will pull up a bunch of associated records in another table. I don't think this should be a problem storing in a single datastore but you might be able to nest your JSON intelligently by placing 1 single master record at the top which relates to many subrecords in an array in the JSON. You can also store additional data outside of your "root" array and access it via the jsonData property. This may be the easiest solution.
http://www.yui-ext.com/forum/viewtopic.php?t=2951&highlight=json

Let us know how things progress and if you need any additional help.

Aaron

Draven
3 Mar 2007, 7:18 AM
http://www.yui-ext.com/forum/viewtopic.php?t=2951&highlight=json

Let us know how things progress and if you need any additional help.

Aaron

Excellent, that post was just what I was looking for. Only now, like you, I have to figure out how to track changes to the form fields since the data marshalling isn't being done by the datasource, unlike the grid data.