PDA

View Full Version : EditorGridPanel and new records



dougd_unc
21 Apr 2011, 6:27 AM
Forgive me if this has been asked, I can't find the answer.

Say I have an EditorGridPanel and some one creates a new record. Now that this data is saved, it has an id in the databse row. I would like to be able to send the id back to the browser so that when the user updates that record, the browser will send the new id to the server, rather than the ext generated id such as ''ext-record-18'

What do I have to send back to the browser to get the EditorGridPanel to refer to the new record with the new database id rather than the ext generated id?

Thanks.

Angilo
21 Apr 2011, 6:38 AM
That totally depends on your update function.

You have defined a column model, in this column model you can add a column containing that ID.

Let's say you have a quick customer edit in the grid.
Define a column named "customer_id" and set it to hidden, I assume you don't want to show this to the user. After it has been inserted, you only need to reload your store.

In your update function you get both the new value and ID (record.data.customer_id in my example), you send both the values via ajax. That's all.

dougd_unc
21 Apr 2011, 6:45 AM
I'm not quite following you. Whenever there is an update operation, I do send an id (hidden) and a name (those are the only two columns). Are you saying I should reload all of the data for the entire grid after I do an insert in order to get the new ids?

Angilo
21 Apr 2011, 6:50 AM
I'm sorry, I misunderstood your problem.

You already passed the stage I described.
What you mean is: the user inserts a record, but the id needs to be retrieved by the database, because your db determines the ID. Reloading an entire grid is an option, but I don't really suggest that. Unless you have a grid with max. 15 rows (which is doable, but still not the best way).

A possible solution could be this.

I assume you send some message back after updating. Success or no success. You can simply add a value to your output, read that output in your update function and replace the ext id with the output.

So: DB returns ID 34 (and you return that value to extjs), but ExtJS assigned ID30, retrieve that row and update the cell.

Tim Toady
21 Apr 2011, 7:00 AM
If you are using something like the jsonwriter, it will automatically update the records as long as you echo them back in the same order in your response. See the response for the create call here
http://dev.sencha.com/deploy/dev/examples/writer/writer.html

dougd_unc
21 Apr 2011, 7:48 AM
I updated the id server side and it worked. Thanks.