Reputation: 6622
I have a grid which I populate by adding items to the store or by receiving already existing items by a server. This is what happens:
1-users adds new items to the grid by gui.
2-users can send new items to the server by pressing a "send" button.
Each item has an "id" property, anyway for newly created items the id is always 0, while for existing one (ie. sent by the server) ids are different.
This leads to the following scenario: when adding a new item extjs accepts it just if there is no other item with the same id...and in my case this is a problem as there can be multiple rows with the same id (0)!
Is there a way to solve this issue? Is there a way to have extjs call its "id" property in another way so that it doesn't conflict with my "id" property?
edit:
partially solved by setting the idProperty value in the model to another field:
idProperty: extid
anyway what troubles me is that if I make
store.getAt(i).getData()
I still get that "extid" property in the resulting json...I don't want to send this field to my server.
Upvotes: 0
Views: 478
Reputation: 19945
There must be a misunderstanding when you say when adding a new item extjs accepts it just if there is no other item with the same id...and in my case this is a problem as there can be multiple rows with the same id
.
In ExtJs, newly created rows always have an id
of zero. This is by design. And there is now problem having more than one row with id=0
. Rows with id = 0
are treated by ExtJs as rows that are not yet saved to the server.
As any database works, the autoincremented id
of a new row is defined at the moment when you insert that row in the database. ExtJs expects that the id column in your table is an autoincremented id, and as such, it expects, that the server sends that row with the now defined id back to the client.
This is how your backend has to work. If it doesn't, you will have a hard time to get it to work nicely together with ExtJs. We don't ask you to alter your server's behavior. ExtJs is requiring the server to behave as expected.
Upvotes: 2
Reputation: 5856
Don't assign any ids for the new items whatsoever. Ext marks such records as phantoms and sends them to the server as new to-be-added records. Server the assigns ids and send them back to Ext. Ext assigns these server-created ids and the records are not new anymore.
Upvotes: 0