How to collapse tree node with no children - extjs

Using ExtJs 4.2.
I have a tree panel where all nodes have arrow for expanding. On expanding a node with children, the arrow for collapsing remains. However, on expanding a node without children, the arrow of the node disappears. So there is no collapsing possible on that node.
How to keep the arrow and collapsing functionality on a node without children?
See the screenshot: both nodes (on the same level, black) are expanded, however only the node with children has a arrow for collapsing again.

AFAIK double-clicking the node toggles expand/collapse. I've tested it in 4.0.0.
Edit:
It has probably changed in Ext4.2 though. The empty folder node seems to be always open (with no children inside). I guess the reason might be to clearly indicate it's empty node to the user (without even interacting with it).

So far we are solving this problem by checking for children on an expand event. If there are no children, we collapse the node again without the user taking note.

Related

react-dropdown-tree-select: Close dropdown on select

Is it possible to access any prop to minimize the dropdown after a node is selected. My use-case is to select only nodes in the deepest level and leaving parent nodes disabled. On selection of a single node, the expected behaviour would be to minimise the dropdown, instead of clicking outside. Can this be achieved with JavaScript without leveraging CSS?

Material-ui - Treeview Expand all

Using material-ui/lab 4.0.0-alpha.27 - TreeView Component
I have a treeview with a couple of hundred nodes. I have added a textfield before the treview that the user can use to search/filter the tree. As they type I add/remove classes from the TreeItems to hide and show TreeItems. It works fine BUT we want all of the nodes to be expanded once they enter something into the search/filter textfield.
I have tried feeding the "defaultExpanded" prop a new list that has all of the nodes in it but it doesn't seem to cause the nodes to expand as I had expected. The defaultExpanded prop only seems to be respected when the tree initially draws.
I am currently working around this by looking for collapsed nodes and firing click events for them to force them to open but that is causing issues (the textfield looses focus and the keyboard hides and the treeview jumps around). I need something a bit smoother.
You need to use the expanded prop, instead of defaultExpanded.

Disabling selection of a node in ExtJS tree panel if the node is not a leaf node

I am using ExtJs 4.1 TreePanel control & want to disable selection of a node if that node is not a leaf node. Do we have any property out of the box to achieve this?
So If the node is not a leaf node, disable selection and if user click on that node, system should not fire any event (itemClick or select etc).
Thank you
There's no property, but you could always key on the beforeitemclick or beforeselect event (or both, depending on what you need to do). Add a handler for this event, check if the clicked node is a leaf, and if it's not, simply return false. That will halt the default behavior and effectively disable the non-leaf nodes.
http://docs.sencha.com/extjs/4.2.2/#!/api/Ext.tree.Panel-event-beforeselect

treepanels drag and drop default behavior

I have two treepanels which I want to drag and drop between. I understand there is a plugin for this, however I want it to behave a certain way.
In my treepanels, I am showing the root node of the tree, and then all its children. The default DD allows the user to drop items at different levels on the tree(i.e. sibling of root, child of root) where I want all items to be a child of root for consistency. How can I make it so that any drag into the treepanel associates the item as a child of the root and not a sibling of the root.
Why:
For a user who doesn't understand how this functionality works, one millimeter in either direction can change the item from being a sibling to child or vice versa.
Also, I would like it so I can only drag away those children and the root can't be moved, if at all possible.
Yes it is possible. You can listen to the 'beforedrop' event on the target Tree panel's tree view and achieve what you want. Something like this
http://jsfiddle.net/EYtnk/1/ ..
One of the arguments of the beforedrop event is the node being dragged. You can check if it is a root node of source tree and just 'return false;'
P.S: In the example, i just used the same store for both the trees.. so the nodes get added on either side.

Checkbox behavior in RadTreeView control

I am using a Telerik RadTreeView control to build a tree with nodes containing checkboxes.
The default behavior for this control is that if you check a parent node, all of the child nodes within it will also become checked. Is there any way to change this behavior? I want to be able to check a parent node on or off and not have it affect the children.
Thanks
I would try doing some magic when the PreviewChecked event happens. I'm not sure, but maybe you can use it to detect a checkbox is about to become checked, and prevent this from happening if it is not the checkbox the user actually clicked in.
You could also do some stuff in javascript like this
function checkNode()
{
var selectedNode = treeView.get_selectedNode();
if (!selectedNode)
{
alert("You need to select a node first.");
return false;
}
selectedNode.set_checked(!selectedNode.get_checked());
return false;
}
This is straight from telerik but simply loop through all the children nodes and turn them back off (or back on when you click it off). The problem is if you want to maintain the state of the children nodes regardless of the parent. Then you need to hold that info in some variable.
The other option is if you don;t want the children to even have checkboxes, then simply don;t make those nodes "Checkable" in the server side code. (I'm sure there is a way in the client side too)

Resources