1.1.3 • Published 3 years ago

mui-draggable-treeview v1.1.3

Weekly downloads
61
License
MIT
Repository
github
Last release
3 years ago

MUI-Draggable-TreeView - Treeview for Material-UI

MUI-Draggable-TreeView is a React Treeview component built on Material-UI TreeView Component with "drag & drop" and ordering functionalities.

Table of contents

Install

npm install mui-draggable-treeview --save

Prerequisites

You need to install @material-ui/core, @material-ui/lab and @material-ui/icons

Demo

Edit react-to-print

Browse live demo

Usage

import { MuiDraggableTreeView, TreeNode } from "mui-draggable-treeview";

export default function TreeViewExample() {
  const data: TreeNode = {
    id: 1,
    name: "Cars",
    children: [
      {
        id: 2,
        name: "Sport Cars",
        children: [
          {
            id: 24,
            name: "Porsche"
          },
          {
            id: 25,
            name: "Ferrari"
          },
          {
            id: 26,
            name: "McLaren"
          }
        ]
      },
      {
        id: 3,
        name: "Classic Cars",
        children: [
          {
            id: 34,
            name: "1957 Corvette"
          },
          {
            id: 35,
            name: "Volkswagen Beetle"
          },
          {
            id: 36,
            name: "Bentley"
          }
        ]
      }
    ]
  };

  return <MuiDraggableTreeView tree={data} enableDragAndDrop={true} />;
}

API

Props

NameTypeDefaultDescription
treeTreeNodeTreeview Data (You will find more details at below)
enableDragAndDropbooleanfalseEnable/Disable "drag & drop" and ordering functionalities

Event Handlers

NameTypeParametersReturnTypeDescription
onNodeDragOver?function(sourceNode: TreeNode, destinationNode: TreeNode)booleanGives control to allow drag over for a destination node. To allow drag over, return true
onNodeDrop?function(tree: TreeNode)voidEvent handler after drop on a Node that passes updated tree data
onNodeReOrderOver?function(sourceNode: TreeNode, destinationNode: TreeNode, isBeforeDestinationNode: boolean)booleanGives control to allow reorder before or after destination node with isBeforeDestinationNode parameter. To allow reordering, return true
onNodeReOrder?function(tree: TreeNode)voidEvent handler after reordering before or after destination Node that passes updated tree data

TreeNode

NameTypeDefaultDescription
idnumberUnique number
namestringLabel of TreeNode item
order?numberundefinedOrder of TreeNode item
data?anyundefinedTreeNode data when it is need
icon?React.ElementTypeundefinedIcon of TreeNode item
children?TreeNode[]undefinedChildren of TreeNode

License

The files included in this repository are licensed under the MIT license.