disable checkbox in angular tree component

1.6k Views Asked by At

I am unable to find any way to disable checkbox node using angular tree component. There is no option to mark the tree disabled so that the checkboxes that appear alongwith th etree data should be disabled. Please suggest

1

There are 1 best solutions below

0
On

Disabling the node can be done by actionMapping inside options attribute https://angular2-tree.readme.io/v1.2.0/docs/options. Here click event of mouse can be overwritten.

<Tree  [nodes]="nodes"  [options]="treeOptions"></Tree>

In my tree data I kept an attribute isSelectable on each node, which is true|false. In case of true i proceed selecting the node otherwise it does not do anything. Here are full options that I am passing to the tree component.

public options: ITreeOptions = {
    isExpandedField: 'expanded',
    idField: 'uuid',
    getChildren: this.getChildren.bind(this),
    actionMapping: {
      mouse: {
        click: (tree, node, $event) => {
          if ( node.data.isSelectable ) {
            this.isNodeSelected.emit(node.data);
            this.alreadySelected = true;
            this.preSelected.tree = tree;
            this.preSelected.node = node;
            this.preSelected.event = $event;
            TREE_ACTIONS.ACTIVATE(this.preSelected.tree, this.preSelected.node, this.preSelected.event);
          }
        }
      }
    },
    nodeHeight: 23,
    allowDrag: (node) => {
      return false;
    },
    allowDrop: (node) => {
      return false;
    }
};