View Full Version : How to duplicate a record in a grid

24 Mar 2014, 1:12 AM
I got a requirement, that after the user has finished editing a row (Ext.grid.plugin.RowEditing -> edit),
this new record should be duplicated automatically but with having two changed values in the record-model.
So that afterwards two records are saved into the backend database all in one go (running with Ext.direct).

Appreciating any hints.

24 Mar 2014, 1:23 AM
how about:

var copyRecord = record.copy();
copyRecord.set('fieldname', value);

24 Mar 2014, 2:43 AM
Thank you. So simple.
Sometimes someone gets stuck in a rut ;)

24 Mar 2014, 6:35 AM
Unfortunately I didn't test it that far, because:

the data model I use has one association ('hasmany') and data there are not copied
by record.copy().

Any ideas how to copy also them?

record.myhasManyAsso().copy() or record.myhasManyAsso().data.copy()
has not the method copy()

24 Mar 2014, 6:39 AM
sorry i dont know how to do this. may be you should start a new question because when people see it as "Answered", they might not read it.

24 Mar 2014, 7:58 AM
I found out, that there are still some issues in 4.1 regading copying data with associations:


(http://www.sencha.com/forum/showthread.php?197869-4.1-RC3-CopyFrom-model-not-copy-hasmany)I found a solution with Ext.clone():

var copyRecord = record.copy();
copyRecord.myHasManyAsso().data = Ext.clone(record.myHasManyAsso().data);

at least it worked for my concerns