PDA

View Full Version : store.getNewRecords



dedoz
16 Dec 2011, 6:58 AM
Hi, im new to extjs also my english is not good.

Why when i load data from server to a grid, the store says they are "new Records"?

example
store.load() // Loads correctly (model, store, phps sets correctly)
store.getNewRecords().length //says all the records are "new".

the problem its if i delete one record, is just reduce the quantity of new records instead of saying a record was deleted, so if do a store.sync() will send the records to insert.

example
store.load() // loads 20 records from sql server
store.getNewRecords().length // its 20, says all of them are new

var sm = grid.getSelectionModel(); // Selected one record on a grid, to remove it
store.remove(sm.getSelection());

store.getNewRecords().length // its 19
store.getRemovedRecords().length // its 0

so store.sync() will end inserting 19 records (it send a create action), instead deleting 1.

can someone help been days trying to delete a record :((

mitchellsimoens
16 Dec 2011, 8:19 AM
This was a bug in 4.0.7. In 4.1.0 beta 1 it has been fixed. getNewRecords().length returns zero and getRemovedRecords().length returns one in my test.

dedoz
16 Dec 2011, 11:46 AM
thank you for answering.

one thing, i solved this it was my mistake, i didnt set the idProperty to the right field, the primary key in my table db had another name. Setting this now most is solved, when i load the records the newRecords remains at 0, and deleting one record, put the removedRecords to 1. (no setting this properly, ends in a getNewRecords doing weird things)

example
store.load() // loads 20 records from sql server
store.getNewRecords().length // its 0, OK

var sm = grid.getSelectionModel(); // Selected one record on a grid, to remove it
store.remove(sm.getSelection());

store.getNewRecords().length // its 0, OK
store.getRemovedRecords().length // its 1, OK
So doing a store.sync() will delete the record correclty.

The new problem is the store.removed (the array that holds the removed records) wont flush after a sync, so if i try to delete a another record and doing a sync() sends 2 records to be deleted in the server (the old one thats its already deleted and the new records i just deleted in the grid)

i guess is something from there the bug in 4.0.7.
solved this just doing store.removed =[] (as it starts in the extjs store code) after a store.sync()
but i dont know at the moment if this gonna get me more problems /:)

thanks for your help still