PDA

View Full Version : XmlDataModel drag and drop bug



nvosker
22 Jan 2007, 10:10 AM
I believe I've run into a bug with drag and drop and XmlDataModel. I have 2 grid with XmlDataModels. Lets say I drag all rows from grid 2 to grid 1, which would leave grid 2 empty, and then try to drag items from grid 1 to grid 2, I get an error...

this.data[0] has no properties
[Break on this error] var template = this.data[0].node;

I believe trying to use this empty target datamodel as a template node is causing the error.

jack.slocum
22 Jan 2007, 12:07 PM
There are like 5 threads in this forum on the topic. I think createNode should return the info you need.

nvosker
22 Jan 2007, 12:59 PM
Jack,

createNode is exactly where the error is being thrown...

var template = this.data[0].node;

I followed your example on the blog Drag and Drop with Grid. The only difference is that I'm using the XMLDataModel

jack.slocum
22 Jan 2007, 1:24 PM
Right, you need to implement createNode to use the drag and drop example with an XMLDataModel...

nvosker
22 Jan 2007, 1:34 PM
Sorry, I'm very confused now. I used your example of ddGri.js in your blog, as is. So I'm on dragdrop it calls transerRows which calls the addRows function which in turn calls the creatNode (where my code breaks). My XmlDataModel.js already has the createNode function...

createNode: function(xmlDoc, id, colData){
var template = this.data[0].node;
var newNode = template.cloneNode(true);
var fields = this.schema.fields;
for(var i = 0, len = fields.length; i < len; 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;
},


Are you saying I need to create a different one? It seems all the pieces are there. The drag and drop works fine until I remove all rows from one grid and then try to put them back.

nvosker
22 Jan 2007, 1:57 PM
Jack,

Just discovered something interesting and maybe this might help identify the problem. I made one change. Instead of loading data in the datamodel from a url, I placed static data in the datamodel, like your example, and it has no problems moving the rows back to an empty grid. Is there something that I need to do when loading data in the data model through a url to make drag and drop not throw this error when the grid is empty?

nvosker
22 Jan 2007, 6:47 PM
Sorry for the confusion, but I finally realized what you were referring to. Just thought there could have been a way to take care of this issue out of the box in the source of XMLDataModel. Here is what I did to make it work for me...

First I added a property to the schema object..
rootName: 'Results'

then I overrode the createNode method to this..

createNode = function(doc, id, colData){
var root = doc.getElementsByTagName(this.schema.rootName)[0];
var tagName = this.schema.tagName;
if(root && tagName){
var newNode = doc.createElement(tagName);
for(x=0;x<this.schema.fields;x++){
newNode.appendChild(doc.createElement(this.schema.fields[x]));
}
for(x=0;x<this.schema.fields;x++){
this.setNamedValue(newNode, this.schema.fields[x], colData[x]);
}
root.appendChild(newNode);
return newNode;
}
};

This way it handled any datamodel i give it as long as set the properties in my schema object for the XmlDataModel appropriately. Do you see any issues with this?