PDA

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



squalo
24 Mar 2014, 1:12 AM
Hi
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.

Farish
24 Mar 2014, 1:23 AM
how about:


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

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

squalo
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()

Farish
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.

squalo
24 Mar 2014, 7:58 AM
Ok.
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

(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