DataPig Instant TreeView Review: Features, Performance, and Use Cases

How to Integrate DataPig Instant TreeView into Your Web App

Integrating DataPig Instant TreeView into a web application provides a fast, interactive way to display hierarchical data (JSON, XML, file trees). This guide assumes a modern JavaScript stack (vanilla JS, React, or Vue) and covers installation, basic configuration, rendering, common features (lazy loading, search, selection), styling, and performance tips.

Prerequisites

  • A web app with a build system (npm/yarn, bundler like Vite/Webpack).
  • Node.js installed for package management.
  • Data source providing hierarchical data (JSON, API endpoint, or filesystem metadata).

1. Install the package

Assuming DataPig Instant TreeView is published to npm, install with:

bash

npm install datapig-instant-treeview # or yarn add datapig-instant-treeview

2. Import and initialize

Vanilla JS:

javascript

import { InstantTreeView } from ‘datapig-instant-treeview’; const container = document.getElementById(‘tree-container’); const tree = new InstantTreeView(container, { data: myTreeData, // array or object representing hierarchy expandOnClick: true, showIcons: true, allowMultiSelect: false, }); tree.render();

React (functional component):

javascript

import React, { useEffect, useRef } from ‘react’; import { InstantTreeView } from ‘datapig-instant-treeview’; export default function TreeComponent({ data }) { const ref = useRef(); useEffect(() => { const tree = new InstantTreeView(ref.current, { data, expandOnClick: true }); tree.render(); return () => tree.destroy(); }, [data]); return <div ref={ref} id=“tree-container” />; }

Vue 3 (composition API):

javascript

<template><div ref=“container”></div></template> <script setup> import { onMounted, onBeforeUnmount, ref } from ‘vue’; import { InstantTreeView } from ‘datapig-instant-treeview’; const container = ref(null); let tree; onMounted(() => { tree = new InstantTreeView(container.value, { data: propsData }); tree.render(); }); onBeforeUnmount(() => tree.destroy()); </script>

3. Data format

Provide hierarchical data as nested objects/arrays. Example JSON structure:

json

[ { “id”: “root”, “label”: “Root Folder”, “children”: [ { “id”: “file1”, “label”: “file1.txt” }, { “id”: “sub”, “label”: “Subfolder”, “children”: [{ “id”: “file2”, “label”: “file2.txt” }] } ] } ]

Key options the component may expect:

  • id — unique node identifier
  • label — display text
  • children — array of child nodes
  • hasChildren — boolean for lazy-load placeholders
  • meta — optional metadata for each node

4. Lazy loading large trees

For big datasets, enable lazy loading:

  • Mark parent nodes with hasChildren: true but omit children.
  • Provide a loadChildren callback that fetches children when a node expands.

Example: “`javascript const

Comments

Leave a Reply