I have a datastore using a connector to work with a MySQL database. The datastore provides services to a grid and a form. Update & delete work perfectly. But adding records is a problem.
The table index (“id”) is an autoIncrement field. But when I use the add() method on the datastore, the system creates an index resembling “-1780040036” which populates the grid. If I query the database externally, I see a different id value resembling “1359724592796”.
Any updates I apply to the row with the -1780040036 id do not apply to the record, and are lost. I have to manually reload the grid, at which time the new index value of 1359724592796 exists, and updates and deletes apply correctly.
- can the system be configured to allow MySQL to generate its own id value? If so, how?
- If question 1 is too involved, how could I automatically refresh the values in the grid so I can retrieve automatically the actual index instead of the bad number?
I found the following, which appears to be similar, but the answer does not involve the use of the data store. Is it necessary to abandon data store to make it all work?
Same logic can be used with datastore as well. It can receive new id from server side and propogate it to the linked components.
Be sure that id field is not editable through form or grid, as above will not work for editable keys.
Stanislav, in your response to the other question, you say:
"Normally after inserting new row, client side code changes id to the value which was set by database ( works only for insert, will not work for update )
“So if you are using default connector saving functionality, new id value will be automatically sent to client side and updated in grid ( assuming that you have auto-increment id column )”
That does not happen when a dataStore is used. When the record is inserted, an id is returned to the grid which does not reflect the id in the database. It appears the dataStore is returning an id which is not the id in the MySQL database, and only when the grid is refreshed does the dataStore go to the connector and get a fresh XML dump with the correct id.
I can write a manual insert into the MySQL database, but if I do that, I need a way to tell the datastore to re-sync with the database. I have tried re-initializing the dataProcessor and re-binding the grid and form, but that is not effective.
I see no methods in the API for dataStore that would cause a refresh, and using sync on the grid is not helpful.
Please show me the sequence for adding records to a grid bound to a datastore which uses a php connector to a MySQL database which results in a grid row with a correct, updated id.
The updated dataStore.js took care of the problem. Thank you.