PDA

View Full Version : Getting the source data...



AspWhiz
23 Nov 2007, 11:50 AM
Not really the source but the dragged data....

I have a view that is an Ext.DataView. It uses a Ext.data.JsonStore that has certain fields. When I drag and item from my view to my tree, I would like to be able to get to the field data when dropped. I'm using nodedrop event of my TreePanel, but am having a hard time figuring how to get to the fields of this item that has been dragged from the DataView. From the event I've tried to use data, source and dropNode. dropNode has given me the correct count of items dragged but I cannot seem to get to any items withing that array that actually contain the fields from my DataView. I was expecting the array to be an array of objects that have properties which I defined as the fields.

Thanks for the help!!!

AspWhiz
23 Nov 2007, 4:15 PM
Seems as if there is a lot of activity in here. Is there noone that can lend me a hand to understand? Please for those of you who are familiar, look at the organizer sample. I've made changes to that but if you simply look at that, when you drag an image from the right over onto a tree node, how do you get all the info about that image? The only thing I can figure out how to get is the auto generated id and the text of the node.

Thanks again. I hope someone will respond with the info to help set me in the correct direction.

SeaSharp
24 Nov 2007, 12:48 AM
My application supports drop events onto a grid from a tree. To confirm the dropped item is a tree node I use the following code. Perhaps the data array of the drag source is lurking in the 3rd data param where I found the "node" attribute.


onNotifyDrop: function( dragSource, e, data ){

if ( data.node )
{
return this.nodeDrop( data.node );
}

AspWhiz
24 Nov 2007, 4:49 AM
First thanks for responding. What I am trying to do I don't think should be this hard to figure out. Like your code, I am using the nodedrop event and referencing the dropNode. I guess my main problem is all I can get to is the node properties, but they just are not enough.

Basically my view panel uses an Ext.XTemplate and this template gets filled with the Ext.data.JsonStore. When I drag this item I cannot figure out IF I can actually get to the JsonStore data or if my only option is getting to the HTML info that is created by using and XTemplate. If the latter is true, my getDragData in drag/drop code is sending back only the html mage (img) element of the html when there is 1 item. When there is more than one it creates a wrapper div around all the images dragged. This info is what I am trying to reference because when you drag, having just the node's text properties (which in my case here is the image name) doesn't help if you need to run an ajax db operation to save your drag.

Thanks again...always.

AspWhiz
24 Nov 2007, 6:43 AM
Unfortunately, I have not found this forum very useful. So far I've figured out all my questions by myself. Now while this is good, it also wastes a lot of time. This is why help from forums and examples are so important. It was not like I was trying to get someone to do my work, but the answer to my problem was extremely simply and no one here could point me in the right direction to save me 3 days of poking around.

For any of you out there who are interested in getting the underlying data store from the dropNode (see the rest of my explanation in this thread of what I parts I was using) in an even like nodedrop or beforenodedrop, you can get there with the following code:



tree.on('beforenodedrop', function(e){
// this is the id of the target node you are dropping onto
alert(e.target.id);

//here we loop through the dropNode which is an array
for(var i = 0; i < e.dropNode.length; i++)
{
//this is the text property of the dropNode array item i
alert(e.dropNode[i].text);

//and here is my revalation for today which I would have though
//someone could have helped me with
//by using the attributes property, you can get to the underlying data store
or any custom attribute added for that matter
var data = e.dropNode[i].attributes["data"];
alert(data.name);
alert(data.id);
}
});

evant
24 Nov 2007, 7:23 AM
Just FYI, you might be more likely to get a response if you post some code initially. While your description of the problem is fine, sometimes it's easier to demonstrate intent from a small portion of your code. It also helps the responder to see what you've got so far, so they can offer a more relevant suggestion.

YMMV :D, but don't give up on the forums just yet.

AspWhiz
24 Nov 2007, 10:17 AM
Oh I won't give up and my hopes are to be more helpful to others once I get a bit more experience. Maybe a lot of folks weren't really using the organizer sampler as a starter. I saw a lot of tree and grid posts, but couldn't get much info out of those except for tree manipulation.

Anyway, I'm digging Ext JS and will do my best to learn what I can!!

:D