PDA

View Full Version : Drag and Drop error for two grids (XMLDataModel)



anotine
17 Nov 2006, 8:07 AM
Hello,

I have a problem after a drag and drop on two grids loaded with load() function.

It occurs, when i try to move an element A from grid 1 to grid 2. A has been previously moved from grid 2 to grid 1. Both Data model are XmlDataModel.

I tried to analize the code (i am new in Javascript stuff), and put some alert notification, i can not manage to make the code pass in the createNode function (during a drop and drag process). It seems that it never call the insertRow function of the datamodel (XMLDATAMODEL) of the target grid, instead it calls the insertRows of the DefaultDataModel...
Is it normal, that it never pass to CreateNode function??

Thank you very much to all.

Jack, It is an amazing work!, thanks a lot!.

anotine
17 Nov 2006, 8:41 AM
Hello Jack,
Well, i found a posible solution:
For me, the ddgrid.js lacks the method addRows and insertRows used in transferRows.
Without that methods overriden, it the base class method (DefaultDataMOdel) that are going to be used. In this case, it think that this method does not update well the Xml document.., that s why i have the node.nodeParent unknown..

Example of addRows function for ddgrid.


YAHOO.ext.grid.XMLDataModel.prototype.addRows=function(rowData){
var newIndex=this.getRowCount()-1;
for (var j=0;j<rowData.length;j++){
newIndex++;
var cellValues = rowData[j];
var node=this.createNode(this.xml,newIndex,cellValues);
cellValues.node=node;
YAHOO.ext.grid.XMLDataModel.superclass.addRow.call(this,cellValues);
}
return newIndex;};

I need some more test to be sure.

jack.slocum
17 Nov 2006, 8:45 AM
I think the multi-adds didn't get implemented because of time constraints.

If you get those 2 working please send me a copy and I will put them through some testing and integrate them. Thanks!

anotine
17 Nov 2006, 9:00 AM
YAHOO.ext.grid.XMLDataModel.prototype.addRows=function(rowData){
var newIndex=this.getRowCount();
for (var j=0;j<rowData.length;j++){
var cellValues = rowData[j];
var node=this.createNode(this.xml,newIndex,cellValues);
cellValues.node=node;
YAHOO.ext.grid.XMLDataModel.superclass.addRow.call(this,cellValues);
newIndex++;
}
return newIndex-1;};

YAHOO.ext.grid.XMLDataModel.prototype.insertRows=function(index,rowData){
var newIndex=index;
for (var j=0;j<rowData.length;j++){
newIndex++;
var cellValues = rowData[j];
var node=this.createNode(this.xml,newIndex,cellValues);
cellValues.id=newIndex||this.getRowCount();
cellValues.node=node;
YAHOO.ext.grid.XMLDataModel.superclass.insertRow.call(this,newIndex,cellValues);
newIndex++;
}
return newIndex-1;};

Hope it helps

jack.slocum
17 Nov 2006, 10:55 PM
I modified those a bit and actually modified most of the XMLDataModel. I added an internal field idSeed used to uniquely auto generate ids. This way if you add rows, then remove some and then add more you don't end up with duplicate ids which would break selections.