How can I remove a class from a treenode while dragging? - extjs

I have a dynamically populated Ext.tree.TreePanel. I can drag nodes from the tree and drop them in a panel but when I drag them, the nodes default iconclass also appears in the drag proxy. How do I remove that class?

I haven't tested this, but just looking through some of the source code, the dragged ghost is obtained via an TreeNode element clone, so you can't tell it explicitly not to add your class, but the first chance you get to delete the class is in the TreePanel.startdrag event:
removeClassOnStartDrag = function(tree) {
tree.dragZone.proxy.ghost.removeClass('some-class');
}
...
treepanel.on('startdrag', removeClassOnStartDrag, this);

Related

appendChild does not put expand collapse icon in tree panel

expand/collapse icon is not shown after adding the child node to tree panel in extjs.
here i have a scenario where i get only immediate childrens of the node. on getting the immediate childrens i want to add those to the selected node.
i can add the child nodes but the expand/collapse icon does not come up after adding the node.
following is my code.
onItemExpand : function(nodeinterface,eOpts)
{
if(!nodeinterface.hasChildNodes())
{
nodeinterface.appendChild(dataFromES[0]);
}
}
here the data contains the property leaf:false so that it can have more childs.
any help is really appreciated.
Thanks
Set the parent node (in your case the nodeinterface variable) "leaf" property to false before you append a new child.
if(!nodeinterface.hasChildNodes())
{
nodeinterface.set('leaf', false);
nodeinterface.appendChild(dataFromES[0]);
}
I've experienced the same problem and in my case the problem was related with the lack of the id property in the nodes.
I've added a random id when creating the nodes to append and then the expand/collapse icon is properly shown.
Alex

In ExtJS 4, How do you delete a tree node when the associated grid information to the node is deleted at random

My code so far populates via drag and drop tree nodes and leaves from a grid panel. I want to know how to remove a tree node when the grid information associated with it is removed.
You should have something like id property in your model both in grid and tree. So when you remove record in the grid you then search for the node with this id in tree and remove it as well. Another way is just save the reference to the node when you drop it.
The flow is:
user drags and drops record from grid to the tree
when the record is dropped and new node is created you save reference in the grid's record
onNodeDrop: function(){
grid.getSelected().treeNode = tree.lastCreatedNode;
}
then when you delete record in grid you could delete node as well.
Note - this is just a psuedocode, is won't work. Just to give you an idea.

Opening tab with tree node data

Hi,
I'm new to both Prism and WPF, and I have a question regarding sharing data between views.
Application I'm working on resembles SQL Server Development Studio. Demo contains two regions. First region contains tree (like Object explorer in SQL Server DS). Tree nodes are bound to different view models. Example would be DatabaseA->Tables->dbo.TableA->Columns etc.
Second region is initially empty. When I double click on tree node I would like to open view that displays data I clicked in tree.
In detail:
1. double click on tree node
2. node data and display it in second region
3. if second region isn't empty, check if clicked node data is already displayed in one of existing tab pages
4. if not, create new tab page with clicked node data, otherwise focus existing tab page
Until now, I managed to created tree. When tree node is clicked app calls:
UriQuery uriQuery = new UriQuery {{"ID", unit.Id.ToString()}};
uriQuery.Add("TypeName", "Unit");
var uri = new Uri("DebugTreeItemView" + uriQuery, UriKind.Relative);
RegionManager.RequestNavigate("SECOND_REGION", uri);
This will open view with tab control and I can fetch uri parameters. But I'm not satisfied with this solution. I need a way to:
1. intercept this RegionManager.RequestNavigate call in order to check if tab control is alread created. Also, I need to check that clicked node data isn't already displayed in one of existing tab pages.
2. I would like to send Unit object directly to tab control view instead of sending ID and typename. What is the best way to achieve this?
Thanks.
I would have a ShellViewModel controlling my overall application. It would contain the TreeNode collection for the left side, and the OpenTabs collection for the right side. It would also contain the SelectedTabIndex for the right side, and perhaps the SelectedTreeNode for the left side if it made sense to do so.
When you want to open a new Tab, I would use the EventAggregator to publish an OpenTab event and pass it the selected TreeNode item. The ShellViewModel would subscribe to those events, and would determine if that object already existed in the OpenTabs collection. If it exists, it simply sets the SelectedTabIndex. If not, it adds the item to the OpenTabs collection before setting the SelectedTabIndex
A while back I posted something here on this sort of navigation with MVVM if you're interested

Drag and Drop grid on a panel

I have a panel and within the panel i have three grids.
I want to be able to move the grid by dragging and dropping.
I have the draggable: true and enableDragDrop: true, that seems to allow me to drag but not drop.
Any genius help will be much appreciated.
In order to drop something that is draggable, you need to define an Ext.dd.DropTarget or Ext.dd.DropZone and define the behavior that you want when the item is dropped. Use DropZone if there are multiple drop targets in a zone that handle the drop differently, but it sounds like you want DropTarget, which is used for dropping on a single element (such as inside your panel).
To make an entire panel be able to drop things onto, pass the panel into the constructor of DropTarget, and override the notifyDrop function:
var panelDropTarget = new Ext.dd.DropTarget(panel, {
notifyDrop: function(dragsource, event, data) {
// do something with the dragsource
}
});
The dragsource that is passed into the function will have your grid in it (I think it will be dragsource.panel, but use Firebug debugging to determine exactly what that source object has in it).
Once you have a handle on the grid, you can reorder it in the panel, move itsomewhere, or define whatever behavior you want.

C# WinForms - TreeView, Context Menu

Suppose I am using a context menu to add child nodes to a treeview control.
(1) I am right-clicking on the node
(2)context menu pop up
(3)then I click "Add" menu item
(4)a dialogBox opens up
(5) I input the name in that DialogBox and press OK
(6) A new Node is created.
How can I get the reference of the current Node when I am clicking on the context menu item?
I need this coz the parent object is stored in the Tag property of the current node.
If you handle TreeNodeMouseClick, then your TreeNodeMouseClickEventHandler will be passed a TreeNodeMouseClickEventArgs argument.
TreeNodeMouseClickEventArgs.Node will be the TreeNode reference you want. See the TreeNodeMouseClick docs for an example similar to:
void treeView1_NodeMouseClick(object sender,
TreeNodeMouseClickEventArgs e)
{
TreeNode theTreeNodeIWant = e.Node
}
If you need to, you can store a reference in a member variable so another method can access it.
You can get the mouse position from
System.Windows.Forms.Cursor.Position
Save this before showing the context menu.
Then use the method on the Treeview containing your items
GetChildAtPoint(Point)
and add a child below that.

Resources