DS01 Custom Path Separators

LTree paths can use any separator, not just dots

Slash-separated Paths
Separator Configuration
Custom Separator Setup
 
Flexibility

Separator Options

  • Dot notation: 1.2.3 (default) - tree-path-separator="."
  • Slash paths: root/auth/login - tree-path-separator="/"
  • Windows paths: C:\Users\Bob - treePathSeparator = "\\" (via JS)
  • Pipe separated: company|dept|team - tree-path-separator="|"
  • Double colon: a::b::c - tree-path-separator="::"
  • Arrow notation: root->child->leaf - tree-path-separator="->"

Use Cases

  • URL-like structures
  • File system paths
  • Namespace hierarchies
  • Custom business logic

Implementation Note

Important: You must set the tree-path-separator attribute (or treePathSeparator property) when using custom separators. Default is "." (dot).

The separator is used for:

  • Calculating node levels automatically
  • Finding parent-child relationships
  • Determining hasChildren property
  • Tree expansion/collapse logic

DS02 Automatic Metadata Calculation

Tree automatically calculates level, parentPath, and hasChildren

Minimal Data
This tree uses minimal data - only id, path, and name are provided. Level, parentPath, and hasChildren are calculated automatically!
What Gets Calculated
Automatic Calculation
 
Automatic Features

Auto-Calculated Properties

  • level: Depth in hierarchy (path segment count)
  • parentPath: Path of parent node
  • hasChildren: Whether node has child nodes

Benefits

  • Reduces data payload size
  • Prevents inconsistencies
  • Simplifies data preparation
  • Always accurate calculations

Performance Note

For large datasets, consider pre-calculating these values on the server to improve client-side performance.

DS03 Pre-calculated Metadata

Optimize performance by providing level, parentPath, and hasChildren

Enriched Data
Optimized data - level, parentPath, and hasChildren are pre-calculated for faster rendering with large datasets.
Manual Optimization
Pre-calculated Data
 
Performance Benefits

When to Pre-calculate

  • Data already available: When server/database already has these values
  • Very large datasets: 15,000+ nodes for noticeable benefit
  • Frequent re-renders: When tree re-renders often
  • Server-side rendering: For better initial load performance

Database Examples

PostgreSQL with LTree:

SELECT
  id,
  path,
  name,
  nlevel(path) as level,
  subpath(path, 0, -1) as parent_path,
  EXISTS(SELECT 1 FROM table t2
         WHERE t2.path <@ table.path
         AND t2.path != table.path) as has_children
FROM table
ORDER BY path;

Performance Impact

Pre-calculation provides minimal performance gain - typically 10-50ms on very large datasets (15k+ nodes). The main benefit is when data is already calculated server-side.

DS04 LTree Path Structure

Understanding the hierarchical path system

Path Visualization
Path Examples
LTree Structure
 
LTree Concepts

LTree Benefits

  • Efficient queries: Find children/ancestors quickly
  • Unlimited depth: No artificial hierarchy limits
  • Sorting friendly: Natural lexicographic order
  • Database compatible: Works with PostgreSQL LTree

Path Rules

  • Use dots to separate levels
  • Start numbering from 1
  • Keep paths short for performance
  • Use consistent numbering scheme

DS05 Windows File System Structure

Real Windows paths with backslash separator

Windows File Tree
Data Structure
File System Data
 
Implementation

Windows File System Features

  • Real paths: Actual Windows file paths
  • Backslash separator: Set via treePathSeparator JS property
  • Mixed types: Drives, folders, files
  • File metadata: Size, type information

Path Examples

  • C: - Drive root
  • C:\\Users - System folder
  • C:\\Users\\Bob - User folder
  • C:\\Users\\Bob\\Documents\\Report.pdf - File

Implementation Notes

  • Escape backslashes in JavaScript strings: use \\\\ in strings for single \\
  • Set treePathSeparator via JS property (not HTML attribute) for backslash
  • Sort by type (drives, folders, files)
  • Handle deep nesting naturally

DS06 Data Structure Comparison

Choose the right approach for your use case

Approach Comparison
ApproachData SizePerformanceUse Case
Minimal DataSmallestExcellent (< 15k nodes)Simple trees, most use cases
Pre-calculatedLargerAlways optimalWhen available from source
Custom SeparatorsVariableGoodURLs, file paths, namespaces
PostgreSQL LTreeOptimizedExcellentDatabase-driven applications
Performance Analysis
Decision Guide
 
Best Practices

Performance Guidelines

  • Auto-calculation: Excellent for < 15k nodes
  • Pre-calculated metadata: Always preferred when available from source
  • Performance penalty: Only ~10-50ms on very large datasets (15k+ nodes)
  • Database queries: Use LTree for complex hierarchies
  • Real bottleneck: Usually rendering, not calculation

Migration Path

  1. Start simple: Use minimal data structure
  2. Measure if needed: Performance is rarely an issue
  3. Pre-calculate when available: Use server data if already computed
  4. Optimize for 15k+ nodes: Only then consider dedicated optimization

Common Patterns

  • File browsers: Slash-separated paths
  • Organizations: Dot notation with pre-calculation
  • Menus: Minimal data with auto-calculation
  • Categories: PostgreSQL LTree for complex queries

Next Steps

Performance
Performance

Optimize data structures for speed

Performance Guide
Search
Search Examples

Search and filter hierarchical data

Search Guide
API
API Reference

Complete documentation

API Docs