PDA

View Full Version : Bug in Drag and Drop



rodiniz
3 Oct 2006, 1:13 PM
I think I found a bug in the drag and drop of thr grid rows.
It happens when you have a grid with more then one column( the only thing different between my code and the sample).
It happens sometimes ...its very strange saying parentNode is null.
You can see for yourself in my page.
http://www.rodrigodiniz.qsh.eu/YahooGrid.aspx

jack.slocum
3 Oct 2006, 7:38 PM
It's actually being thrown in the XMLDataModel. When you remove a row it also removes the node from the xml document. When a drag and drop operation completes, DDGrid removes the row then re-inserts it in the the new spot. The default createNode() on XMLDataModel is very basic and appears to not be effective on your xml document. Here's the code for the default createNode:



var template = this.data[0].node;
var newNode = template.cloneNode(true);
var fields = this.schema.fields;
for(var i = 0; i < fields.length; i++){
var nodeValue = colData[i];
if(this.postprocessors[i]){
nodeValue = this.postprocessors[i](nodeValue);
}
this.setNamedValue(newNode, fields[i], nodeValue);
}
if(id){
this.setNamedValue(newNode, this.schema.idField, id);
}
template.parentNode.appendChild(newNode);
return newNode;


All it does is clone the first row's node, set the new values on that clone and appends it to the parent of the original node. I'm not sure why that is failing in your case, your xml document looks pretty basic.

If you look at the Drag and Drop w/ Grid Part 2 I included a small part about overriding and implementing your own createNode(), which is the preferred method. Give that a try and let me know if it corrects your problem.

rodiniz
5 Oct 2006, 3:48 AM
Hi Jack I think I solved the bug.
It was an error in the removeRow function.
Aperantly my fix has no side effects.
You can see the fix in GridExtension.js..only one line of code
is different from the original.

jack.slocum
5 Oct 2006, 3:59 AM
Hi Rodrigo,
That stops the JS error from appearing, which is good, however the condition that caused the node to be missing still exists. Did you try implementing a createNode function as I suggested?

rodiniz
5 Oct 2006, 4:43 AM
Hi Jack...since the error disappeared and the drag and drop is working
I tested lots of times.I saw no reason to do nothing else.
I looked at your post and I saw no reference what so ever about implementing a createNode ...
The js Error is gone and it seems that nothing is affected by the missing node.

anotine
17 Nov 2006, 7:38 AM
Hello,

I have the same problem:

Exactly, 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??

rodiniz ( i am sorry), would you share the correction you made in the removeRow?

Thank you very much to all.

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

rodiniz
17 Nov 2006, 10:01 AM
Looks like from another post that you have fixed the problem.
But here is my simple solution.Just add this after inserting the reference to yui-ext.js


YAHOO.ext.grid.XMLDataModel.prototype.removeRow = function(index){
var node = this.data[index].node;
if(node.parentNode !=null)
node.parentNode.removeChild(node);
YAHOO.ext.grid.XMLDataModel.superclass.removeRow.call(this, index, index);
};

ps: the solution its on the page on the previous post....on GridExtensions.js