jansepke
jansepke

Reputation: 1979

Store does not get new ID after create

I have a editable grid with store + model + REST-Proxy.
Get, update and delete is no problem, but if I do:

store.insert(0, {});
cellEditing.startEditByPosition({
    row: 0,
    column: 1
});

the server respond with:

{
"success":true,
"results":0,
"root":"data",
"message":null,
"data":{"TerritoryUserPK":"7f064ddd-d5c9-47ae-94cc-29da14d27962"},
"debug":null
}

where "TerritoryUserPK" is the idProperty of the model.
I would now expect that the store will use this id for the new object, but it remains "ext-record-1".

How must the server response look like, so the Ext Store excepts the new ID?
The reader is this:

reader: {
    type: 'json',
    root: 'data',
    messageProperty: 'message',
    totalProperty: 'results'
}

Upvotes: 1

Views: 1017

Answers (2)

jansepke
jansepke

Reputation: 1979

Found the problem, store.load() gets an object with metadata so that the root property of the reader gets set to "rows". After the POST request the server respond with an object without metadata and the data in a "data" property. The reader remembers the last root property and will search for "rows" and cant find the property.

So be always aware of values set by metadata.

Upvotes: 1

rixo
rixo

Reputation: 25001

Try setting a clientIdProperty in your model, and return the id generated by ext back into the data...

For example, in your model:

clientIdProperty: 'clientId'

In your response:

data: [{id: 123, clientId: 'ext-record-1', ...}]

I don't remember if the client id is sent to the server in the configured idProperty (I think so) or the clientIdProperty... Inspect the browser request to be sure!

Upvotes: 0

Related Questions