PDA

View Full Version : need help configuring JsonStore + EditorGrid



Bogdan0x400
21 Feb 2011, 8:24 AM
I have an editorgrid which is configured like this:

store: {
xtype: 'jsonstore',
fields: [
{ name: 'ContactID', type: 'int' },
{ name: 'Price', type: 'int' }
],
idProperty: 'ContactID',
data: { result: SomeData || [] }
}
This grid is used when creating an entity or loading it's details for edit.
The user selects ContactID from the combobox items, which are loaded using another JsonStore. I can list a complete source if need be.
Creation works fine, the data seems to be saved correctly. But when the grid is opened for edit, then it just doesn't display anything, and this is the problem. When the grid is opened for edit then stuff like "[{ContactID:1, ContactName:"person's name", Price:100}] gets passed as the SomeData parameter. Any guesses as to why it doesn't display anything?

Condor
21 Feb 2011, 8:27 AM
Because it's missing:

root: 'result'

Bogdan0x400
21 Feb 2011, 8:47 AM
root: 'result'
Unfortunately that didn't help :( .

Bogdan0x400
21 Feb 2011, 8:55 AM
Now my grid has an infinite number of rows with default values.

Condor
21 Feb 2011, 9:33 AM
That's not normal. Are you sure SomeData is an array and not a string?

Bogdan0x400
21 Feb 2011, 9:46 AM
Indeed, you are right, it is a string that contains a JSON object. Is there a way to configure the JsonStore to use a string that describes a JSON object as a store parameter?

Condor
21 Feb 2011, 10:32 AM
Ext.decode(SomeData)

Bogdan0x400
22 Feb 2011, 1:11 AM
Great, now it really works, thanks! Now I have only one last small question:
The ID is loaded fine in the Contact field, but contact's name isn't loaded automatically by the ID. The contact field has a combobox editor which is configured to use another JsonStore to load the contact names and IDs using an AJAX request to the web server. So what is the best practice to load the contact name? Loading the contact name on the server is actually not a good idea in my case, so I would prefer to do it in the client script.

Bogdan0x400
22 Feb 2011, 1:52 AM
Discovered another problem:
When I load the old data to the grid and then do a post back, then the data about old records doesn't get posted to the server. Only the data about newly created records gets passed, though both old and new records are displayed in the grid. How do I post both old and new and is this behaviour correct and by default? By new records I mean the records that were created by the user in the grid after the old records data was loaded.