I use a form to add and edit records, because the model contains much more fields then the gridpanel.
I use MVC.
My problem concentrates on inserting records.
When the user pushes the add button:
I create a new model:
Code:
var store = gridpanel.getStore();
var model = Ext.ModelMgr.getModel(store.model);
var record = model.create();
store.insert(0, record);
open the form and load the record to the form:
Code:
frm.loadRecord(record);
When the form is submitted:
the record is updated:
Code:
frm.updateRecord()
var record = frm.getRecord()
now I come in to troubles:
1. when i use record.save(), two things go wrong:
1.1
I've noticed that after frm.getRecord() the record is still associated to the store (I can see by record.store), but something also goes wrong with this association (record.store.indexOf(record) = -1). When I call record.destroy() the record is removed in the database, but isn't removed from the store. So I come in trouble with the delete functionality of the grid (for so far there are newly add records in the grid).
1.2
The php api returns the id of the inserted record and this is needly updated in the model which now contains an id (corresponding with the database). But somehow the model is still considered new. When I push the submit button the model is inserted again (the create api is called). record.commit() doesn't seem to solve this.
2. when I use store.sync(); record.commit(); problems 1.1 and 1.2 are solved, but the id of the model isn't updated (as in 1.2). So I come in trouble with the edit functionality of the grid (for so far there are newly add records in the grid).
Can anyone tell me what to do? I've tried a million thinks, all combination of store.sync(), record.save(), record.commit(), store.remove(), record.destroy() and time and places to insert the new record (store.insert()). Thanks in advance.
Troubles with combination grid, store, form when inserting records
Aucun commentaire:
Enregistrer un commentaire