View Full Version : Add Grid row from one grid to another

2 Aug 2007, 4:07 PM
Ok, first I would like to say that I am new here. And would like to say that I really like what I have been able to do with this library.

Having dabled with dojo for a long time, I am impressed with a lot of the features in here.

Now to my problem..

I have 2 grids, one that is being populated with specific data and another that I would like to drag data too. I have no problems getting this to work, except I discovered one little problem that I am unable to find a solution for.

When I copy a row from one grid to the next, and that row already exists I get an error in firefox that says

r has no properties

I can see the problem, because the ID is the same as what is being dropped now the problem I am facing is that I can't seem to find a way to make the second grid generate a new ID rather than take the ID from the dropped record.

My code for handling the drop is as follows, but I have tried many scenarios and have giving up for now and would like to know if there is a way for me to allow the item to be dropped a second time...

var drop = new Ext.dd.DropTarget(grid.container, {
ddGroup : 'GridDD',
notifyDrop : function(dd, e, data){
dsWallet.add(data.selections); // This line fails if trying to drop a record add a record with the same Id...

3 Aug 2007, 3:28 PM
I am not having much luck, surely someone knwos how to add a duplicate record and change the ID from one grid to another :-(

3 Aug 2007, 3:34 PM
I don't believe you can, I think the id in a store must be unique. Can you change the id on the row before you copy it over? Or prefix it, say '1' becomes 'X1'

3 Aug 2007, 3:56 PM
I realise it must be unique, but the code above copies the ID as well when adding it.

So my question still remains, how do I change the ID or even remove it so that the add will make it unique again.

3 Aug 2007, 4:13 PM
Well I'm assuming selections is an array of records, so why not just loop through each one, 'copy' each record and then change the id.

3 Aug 2007, 5:08 PM
I have tried that and it doesn't work either.

3 Aug 2007, 6:03 PM
Of course it will work, you're creating a new record and putting it into a grid, why don't you post that bit of code?

3 Aug 2007, 6:48 PM
Finally found the solution that was missing

var newRecord = record.copy();
newRecord.id = null;

instead of
record.id = null;

3 Nov 2009, 5:21 AM
a little more informatiion on this would be helpful... Can u tell me where
"var newRecord = record.copy();
newRecord.id = null;" comes ? It gives an error sayinf record.copy() is not a funtion..

4 Nov 2009, 1:36 AM
Can u share the complete code so that we can see how it works?