A lightweight, dependency-free TreeView component for the web — built with OutSystems in mind, but happy anywhere.
npm install treezleOr via CDN:
<script src="https://cdn.jsdelivr.net/npm/treezle/dist/treezle.iife.js"></script>
- Zero dependencies — pure JS and CSS, works in any environment
- Flat node array — maps 1:1 to a database table or OutSystems Entity
- Drag & drop — with circular-drop protection (we've thought of the edge cases)
- Inline rename — double-click to rename, Enter to confirm, Escape to bail
- Multi-select — Ctrl+click support
- Keyboard navigation — arrow keys, Home/End, Enter and Space
- Checkboxes — per-node, with global column reservation for alignment
- Context menus — right-click, ellipsis button (horizontal or vertical), or none
- Themes —
minimal,explorer, andborderout of the box - CSS variables — every color, size, and spacing is customizable via
.tv-container - Icon support — works with any CSS icon library (e.g. Remix Icon) or image URLs
- DOM events — all events fire as
CustomEventon the container with atreezle:prefix
| File | Description |
|---|---|
treezle.js |
Component logic — exports window.TreeView |
treezle.css |
All styling — no inline styles in JS (except dynamic paddingLeft) |
| File | Use |
|---|---|
dist/treezle.iife.js |
OutSystems JavaScript resource or a browser script tag; exposes window.TreeView |
dist/treezle.es.js |
Browser ES module; provides named and default TreeView exports and the same global for existing wrappers |
dist/treezle.css |
Component styles; load your icon library separately if you use icons |
The source files and the React/Angular wrappers remain available. Open demo/index.html for the standalone HTML component lab: all 17 API operations, four presets, four layouts, three themes, every option and a live event inspector. No installation, build step, server or OutSystems environment is needed to open the demo. The original two-tree examples remain in demo/basic.html. See demo/README.md for the demo controls and API examples.
<link rel="stylesheet" href="treezle.css" />
<script src="treezle.js"></script>
<div id="my-tree"></div>
<script>
const nodes = [
{ id: "1", parentId: null, label: "Root", nodeType: "folder", isExpanded: true },
{ id: "2", parentId: "1", label: "Child A", nodeType: "item" },
{ id: "3", parentId: "1", label: "Child B", nodeType: "item" },
];
const tree = new TreeView(
document.getElementById("my-tree"),
nodes,
{ theme: "minimal", showIcons: false },
[]
);
tree.on("onNodeClick", ({ node }) => {
console.log("Clicked:", node.label);
});
</script>Every node is a plain flat object — no nesting, no subNodes, no surprises.
| Field | Type | Default | Description |
|---|---|---|---|
id |
string | number |
auto | Primary key. Long Integer compatible (OutSystems) |
parentId |
string | number | null |
null |
Parent node id. null = root node |
label |
string |
"Node" |
Display text |
nodeType |
string |
"" |
Used to filter commands per node type |
isReadOnly |
boolean |
false |
Disables inline rename |
isDraggable |
boolean |
false |
Enables drag source |
isExpanded |
boolean |
false |
Expanded state |
isSelected |
boolean |
false |
Selected state |
isDisabled |
boolean |
false |
Grays out and disables interaction |
isVisible |
boolean |
true |
Hides the node without removing it |
isChecked |
boolean |
false |
Checkbox state |
showCheckBox |
boolean |
false |
Show checkbox for this node |
cssClass |
string |
"" |
Extra CSS class on the row element |
icon |
string |
"" |
CSS class (e.g. ri-folder-line) or image URL |
isDropTarget |
boolean |
true |
Set to false to reject drops onto this node |
data |
object |
{} |
Free JSON payload — not touched by Treezle |
Pass as the third argument to new TreeView().
| Option | Type | Default | Description |
|---|---|---|---|
multiSelect |
boolean |
false |
Enable Ctrl+click multi-select |
allowInlineRename |
boolean |
false |
Enable double-click rename |
indentPx |
number |
20 |
Indent per level in pixels |
showIcons |
boolean |
false |
Render icon column |
showCheckBoxes |
boolean |
false |
Reserve checkbox column globally |
menuStyle |
string |
"None" |
"None" | "RightClick" | "EllipsisButton1" | "EllipsisButton2" |
styleClass |
string |
"" |
Extra CSS class added to the container |
theme |
string |
"minimal" |
"minimal" | "explorer" | "border" |
sortOrder |
string |
"alphabetical" |
"alphabetical" sorts sibling labels; "input" keeps supplied order |
Changing sortOrder immediately reorders existing nodes without losing edits. New or moved nodes are appended to their parent; renames retain their position until the sort order changes or nodes reload.
Commands populate the context menu. Pass as the fourth argument.
| Field | Type | Description |
|---|---|---|
name |
string |
Unique identifier — returned in the onCommand event |
label |
string |
Menu item display text |
nodeType |
string |
"" = show for all node types, otherwise filter by nodeType |
icon |
string |
CSS class or image URL |
iconHover |
string |
Alternative icon swapped in on hover (optional) |
show |
boolean |
false = never show this command |
const commands = [
{ name: "rename", label: "Rename", nodeType: "", icon: "ri-pencil-line" },
{ name: "delete", label: "Delete", nodeType: "item", icon: "ri-delete-bin-line" },
{ name: "addChild", label: "Add child", nodeType: "folder", icon: "ri-add-line" },
];All events fire as DOM CustomEvent on the container element with the prefix treezle:.
They also call any handlers registered via .on().
// Option A — DOM event (great for OutSystems)
container.addEventListener("treezle:onNodeClick", (e) => {
console.log(e.detail.node);
});
// Option B — fluent API
tree.on("onNodeClick", ({ node }) => {
console.log(node.label);
});| Event | Payload | Description |
|---|---|---|
onNodeClick |
{ node } |
Node was clicked |
onNodeSelect |
{ node, selectedIds[] } |
Selection changed |
onNodeExpand |
{ node } |
Node expanded |
onNodeCollapse |
{ node } |
Node collapsed |
beforeNodeExpand |
{ node, preventDefault() } |
Before expand — call preventDefault() to cancel |
beforeNodeCollapse |
{ node, preventDefault() } |
Before collapse — call preventDefault() to cancel |
onNodeRename |
{ node, oldLabel, newLabel } |
Inline rename committed |
onStartDrag |
{ node } |
Drag started |
onNodeMoved |
{ node, fromParentId, toParentId, nodes[] } |
Node dropped on new parent |
onDropNode |
{ draggedNode, targetNode, nodes[] } |
Raw drop event |
onDropRejected |
{ reason, draggedNode, targetNode } |
Drop rejected (e.g. circular) |
onCommand |
{ node, commandName } |
Context menu command clicked |
onCheckChanged |
{ node, isChecked } |
Checkbox toggled |
onNodeAdded |
{ node, parentId } |
Node added via addNode() |
onNodeDeleted |
{ node, nodes[] } |
Node (and descendants) deleted via deleteNode() |
onNodeChanged |
{ node } |
Node updated via editNode() |
Note:
nodes[]in move/drop events is the full updated flat array — ready to sync back to your server.
const tree = new TreeView(container, nodes, options, commands);
tree.setNodes(nodes) // Replace all nodes and re-render
tree.setOptions(options) // Merge new options and re-render
tree.setCommands(commands) // Replace command list
tree.getNodes() // → flat array of all nodes (current state)
tree.getChangedNodes() // → flat array of nodes with _dirty = true
tree.expand(id) // Expand a node by id
tree.collapse(id) // Collapse a node by id
tree.selectNode(id) // Programmatically select a node
tree.toggleSelect(id) // Toggle selection state of a node
tree.addNode(parentId, nodeJSON) // Add a node under parentId (null = root)
tree.deleteNode(id) // Delete a node and all its descendants
tree.editNode(nodeData) // Merge fields into existing node — { id, ...fields }
tree.on(event, handler) // Subscribe to an event
tree.off(event, handler) // Unsubscribe
tree.destroy() // Clean up DOM and global listeners
TreeView.getInstance(id) // Get a TreeView instance by container element idAll visual properties are CSS custom properties scoped to .tv-container — so multiple instances on the same page can each have their own theme. Context menu variables are additionally declared on :root since the menu renders on document.body.
/* Example: warm orange selection */
#my-tree {
--tv-selected-bg: #ffc782;
--tv-hover-bg: #ffe0b5;
--tv-drop-border: #ff9023;
}
/* Example: compact dense tree */
#my-tree {
--tv-line-height: 22px;
--tv-font-size: 12px;
--tv-indent: 16px;
}| Variable | Default | Description |
|---|---|---|
--tv-bg |
#ffffff |
Container background |
--tv-color |
#1a1a1a |
Default text color |
--tv-font-size |
13px |
Base font size |
--tv-line-height |
26px |
Row height |
--tv-indent |
20px |
Indent per level in pixels |
--tv-hover-bg |
#f0f0f0 |
Row hover background |
--tv-selected-bg |
#e0e0e0 |
Selected row background |
--tv-selected-color |
#000000 |
Selected row text color |
--tv-drop-border |
#ff9023 |
Drop target outline + checkbox accent |
--tv-drop-bg |
#e5f3fb |
Drop target background |
--tv-arrow-color |
#888 |
Expand/collapse arrow color |
--tv-menu-bg |
#ffffff |
Context menu background |
--tv-menu-shadow |
— | Context menu box shadow |
--tv-ellipsis-color |
#999 |
Ellipsis button color |
Full variable list is in src/treezle.css.
Treezle doesn't ship an icon library — bring your own. Any CSS icon library works (Remix Icon, Font Awesome, Lucide, …), and so do plain image URLs.
dist/treezle.css contains no icon imports, so nothing extra gets loaded unless you ask for it. The examples and the OutSystems reference implementation use Remix Icon:
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/remixicon@4/fonts/remixicon.css" />Then set the icon field on a node (or command) to a class name or an image URL:
// Remix Icon
{ icon: "ri-folder-line" }
// Font Awesome
{ icon: "fa-solid fa-folder" }
// Image URL
{ icon: "https://example.com/icons/folder.svg" }Note:
src/treezle.cssstill contains@import url("../remixicon.css")for the OutSystems setup. If you use the source files directly, remove or adjust that line.
Treezle was designed with OutSystems in mind. Recommended wiring:
OnReady (JavaScript node)
var host = $parameters.ElementId; // reference to container element
var nodes = JSON.parse($parameters.NodesJSON);
var options = JSON.parse($parameters.OptionsJSON);
var commands = JSON.parse($parameters.CommandsJSON);
host._treezle = new TreeView(host, nodes, options, commands);
window.treezle = host._treezle; // optional global reference
host.addEventListener("treezle:onNodeClick", function(e) {
$actions.OnNodeClick(JSON.stringify(e.detail.node));
});
host.addEventListener("treezle:onCommand", function(e) {
$actions.OnCommand(JSON.stringify(e.detail.node), e.detail.commandName);
});OnParametersChanged
var host = $parameters.ElementId;
if (host._treezle) {
host._treezle.setNodes(JSON.parse($parameters.NodesJSON));
}Client Action — SelectNode
var host = $parameters.ElementId;
if (host._treezle) {
host._treezle.selectNode($parameters.NodeId);
}Nodes come in via JSONSerialize in a Server Action and go out the same way — Treezle's flat array maps 1:1 to an OutSystems Entity.
All modern browsers. No IE11. Life is too short.
MIT — Micha Sulman, 2026