### Initialize jstree with Table Plugin (Left Example) Source: https://github.com/cuiyonghua/jstree-table/blob/master/demo/dnd-test.html Initializes a jstree instance with the 'table' plugin, configuring columns, checkbox behavior, and core settings. This example demonstrates a tree with 'cascade: "down"' for checkbox selection. ```javascript $(document).ready(function(){ $("#js1").jstree({ plugins: ["table", "dnd", "types", "checkbox", "wholerow", "contextmenu"], "checkbox": { "three_state": false, "cascade": "down", "tie_selection": false, "whole_node": false }, 'table': { 'columns': [ { 'header': 'Column 1' }, { 'header': 'Column 2', 'value': 'col2' }, { 'header': 'Column 3', 'value': 'col3' } ], 'resizable': true, 'contextmenu': true }, 'core': { "check_callback": true, 'data': [ { "text": "This 1 column is ok.", "state": {"selected": true, "opened": true, "checked": false}, "parent": "#", "id": "0011100001CaxJLAA2", "data": {"col2": "I will be lost 1!", "col3": "Me too 1!"} }, { "text": "This 1 column is ok too!", "state": {"selected": true, "opened": true, "checked": true}, "parent": "0011100001CaxJLAA2", "id": "0011600001lNOsfAA1", "data": {"col2": "I will be lost again 1!", "col3": "Me too! No 1!!"} } ] }, "types": { "#": {"max_children": 1, "valid_children": ["default", "hidden", "root", "visible"]}, "default": {"valid_children": ["default", "hidden", "root", "visible"]} }, 'contextmenu': { 'items': {} } }); }); ``` -------------------------------- ### Initialize jstree with Table Plugin (Right Example) Source: https://github.com/cuiyonghua/jstree-table/blob/master/demo/dnd-test.html Initializes another jstree instance with the 'table' plugin, similar to the left example but with 'cascade: "up"' for checkbox selection. This demonstrates an alternative checkbox behavior. ```javascript $(document).ready(function(){ $("#js2").jstree({ plugins: ["table", "dnd", "types", "checkbox", "wholerow", "contextmenu"], "checkbox": { //"three_state" : false, "cascade": "up", "tie_selection": false, "whole_node": false }, 'table': { 'columns': [ { 'header': 'Column 1' }, { 'header': 'Column 2', 'value': 'col2' }, { 'header': 'Column 3', 'value': 'col3' } ], 'resizable': true, 'contextmenu': true }, 'core': { "check_callback": true, 'data': [ { "text": "This column is ok.", "state": {"selected": true, "opened": true, "checked": false}, "parent": "#", "id": "0011100001CaxJLAAZ", "data": {"col2": "I will be lost!", "col3": "Me too!"} }, { "text": "This column is ok too!", "state": {"selected": true, "opened": true, "checked": true}, "parent": "0011100001CaxJLAAZ", "id": "0011600001lNOsfAAG", "data": {"col2": "I will be lost again!", "col3": "Me too! No!!"} } ] }, 'dnd': { "copy": false }, "types": { "#": {"max_children": 1}, "default": {"valid_children": ["default", "hidden", "root", "visible"]} }, 'contextmenu': { 'items': {} } }); }); ``` -------------------------------- ### Basic jsTreeTable Initialization Source: https://context7.com/cuiyonghua/jstree-table/llms.txt Initializes a basic jsTree with table columns. This involves including the 'table' plugin and defining column configurations that map to node data properties. The example shows how to set up columns for 'Name', 'Price', and 'Qty'. ```javascript // Include required dependencies in HTML // // // // Define tree data with custom data attributes for columns var data = [{ id: "Products", text: "Products", data: {}, children: [{ id: "Fruit", text: "Fruit", data: {}, children: [ {id: "Apple", text: "Apple", data: {price: 0.1, quantity: 20}}, {id: "Banana", text: "Banana", data: {price: 0.2, quantity: 31}}, {id: "Grapes", text: "Grapes", data: {price: 1.99, quantity: 34}}, {id: "Mango", text: "Mango", data: {price: 0.5, quantity: 8}} ], 'state': {'opened': true} }], 'state': {'opened': true} }]; // Initialize jstree with table plugin $("div#jstree").jstree({ plugins: ["table"], core: { data: data }, table: { columns: [ {width: 200, header: "Name"}, {width: 150, value: "price", header: "Price"}, {width: 150, value: "quantity", header: "Qty"} ] } }); ``` -------------------------------- ### jsTree Table: Initialize with Data and Columns (JavaScript) Source: https://github.com/cuiyonghua/jstree-table/blob/master/demo/widths-test.html Initializes a jsTree table with predefined data and column configurations. This example demonstrates setting fixed widths for all columns and includes options for resizable columns and context menus. It requires the jsTree core, themes, json, and table plugins. ```javascript var data = [ { text: "Root 1", data: {price: "$5.00", size: "4",spanclass:"root"}, children: [ { text: "Really long named child whose name gets cut off", data: {price: "$4.00", size: "3",spanclass:"first"} }, { text: "Child 2", data: {price: "$3.00", size: "2",spanclass:"second"}, children: [ { text: "Grandchild", data: {price: "EXPENSIVE!", size: "10",spanclass:"third"} } ] } ] } ]; $(document).ready(function(){ $('#tree').jstree({ plugins: ["themes", "json", "table"], core: { data: data }, table: { width: 400, columns: [ {width: 150, header: "Nodes", title: "_DATA_"}, {width: 100, cellClass: "col1", value: "price", header: "Price", title: "price", valueClass: "spanclass"}, {width: 75, cellClass: "col2", value: "size", header: "Qty", title: "size", valueClass: "spanclass"} ], resizable: true, contextmenu: true } }); }); ``` -------------------------------- ### Full Configuration Options for jsTreeTable Source: https://context7.com/cuiyonghua/jstree-table/llms.txt Provides a comprehensive example of all available configuration options for the jsTreeTable plugin. This includes settings for dimensions, column definitions, and various features like resizing, reordering, and state saving. It also shows how to configure icons for context menus and sorting indicators. ```javascript $('#jstree').jstree({ plugins: ["table"], core: { data: treeData, check_callback: true }, table: { // Dimensions width: 800, // Total table width in pixels (default: auto/100%) height: 400, // Total table height in pixels (default: auto) columnWidth: 100, // Default column width when not specified // Column definitions columns: [ { tree: true, // Place jstree in this column (default: first column) width: 200, // Column width in pixels header: "Name", // Header text headerClass: "", // CSS class for header columnClass: "", // CSS class for column cellClass: "", // CSS class for cell span wideCellClass: "", // CSS class for cell div value: "propName", // Node data property to display format: function(v) { return v; }, // Value formatter valueClass: "", // Node data property for dynamic class valueClassPrefix: "", // Prefix for valueClass wideValueClass: "", // Node data property for div class wideValueClassPrefix: "", // Prefix for wideValueClass title: "titleProp", // Node data property for cell title/tooltip sort: function(a, b, nodeA, nodeB) { return a > b ? 1 : -1; } // Custom sort } ], // Features resizable: true, // Allow column resizing (default: false) draggable: true, // Allow column reordering - requires jQuery UI (default: false) stateful: true, // Save column widths to localStorage (default: false) fixedHeader: true, // Keep headers visible on scroll (default: true) contextmenu: true, // Enable cell editing context menu (default: false) headerContextMenu: true, // Enable header context menu (default: true) // Icons (Font Awesome classes) checkIcon: 'fa fa-check', arrowUpIcon: 'fa fa-chevron-up', arrowDownIcon: 'fa fa-chevron-down' } }); ``` -------------------------------- ### Configure Table Columns with Value Source: https://github.com/cuiyonghua/jstree-table/blob/master/README.md This JavaScript example shows how to configure the 'table' options for jsTreeTable, specifically defining columns and mapping a 'price' property from the node data to a 'Price' column. ```javascript table: { columns: [ {width: 50, header: "Nodes"}, {width: 30, header: "Price", value: "price"} ] } ``` -------------------------------- ### Initialize jstree-table with Data and Columns Source: https://github.com/cuiyonghua/jstree-table/blob/master/demo/grid-api-test.html Initializes a jstree instance with hierarchical data and configures it to display as a table using the 'table' plugin. It defines the columns, their widths, headers, and the data fields to display. This setup is crucial for rendering structured tabular data within a tree. ```javascript $(document).ready(function(){ var data = [ { "id" : "Root", "parent" : "#", "text" : "Root"}, { "id" : "child1", "parent" : "Root", "text" : "child1", "data" : { "open" : "2/5/2015 2:18:00 PM", "close" : "2/6/2015 10:16:00 AM", "status" : "Closed"}}, { "id" : "child1-1", "parent" : "child1", "text" : "child1-1", "data" : { "open" : "2/5/2015 2:18:00 PM", "close" : "2/6/2015 10:16:00 AM", "status" : "Closed"}}, { "id" : "child2-2", "parent" : "child1", "text" : "child2-2", "data" : { "open" : "2/5/2015 2:18:00 PM", "close" : "2/6/2015 10:16:00 AM", "status" : "Closed"}}, { "id" : "child2", "parent" : "Root", "text" : "child2", "data" : { "open" : "2/5/2015 2:18:00 PM", "close" : "2/6/2015 10:16:00 AM", "status" : "Closed"}}, { "id" : "child3", "parent" : "Root", "text" : "child3", "data" : { "open" : "2/5/2015 2:18:00 PM", "close" : "2/6/2015 10:16:00 AM", "status" : "Closed"}} ] $('#jstree').jstree({ "core" : { "data" : data }, "plugins" : [ "table" ], "search" : { "show_only_matches" : false }, "table" : { columns: [ {width: 190, header: "name"}, {width: 140, header: "open", value: "open"}, {width: 140, header: "close", value: "close"}, {width: 130, header: "status", value: "status"} ] } }); }); ``` -------------------------------- ### Include jsTreeTable Script Source: https://github.com/cuiyonghua/jstree-table/blob/master/README.md This snippet shows how to include the jsTreeTable JavaScript file in your HTML. Ensure the path is correct for your project setup. ```html ``` -------------------------------- ### jsTreeTable Column Formatting Source: https://context7.com/cuiyonghua/jstree-table/llms.txt Configures jsTreeTable columns with custom formatting functions. This allows for transforming raw data values into display strings, such as currency or unit indicators. The example demonstrates formatting for 'Price' and 'Qty' columns. ```javascript $("div#jstree").jstree({ plugins: ["table", "sort"], core: { data: data, check_callback: true }, table: { columns: [ {width: 200, header: "Name"}, { width: 150, value: "price", header: "Price", format: function(v) { if (v) { return '$' + v.toFixed(2); } } }, { width: 150, value: "quantity", header: "Qty", format: function(v) { return v ? v + ' units' : 'N/A'; } } ], width: 500, height: 300 } }); ``` -------------------------------- ### Handle Column Resize Events in jsTree Table Source: https://context7.com/cuiyonghua/jstree-table/llms.txt Listen for column resize events to persist column widths or trigger layout updates. This example shows how to log resize events and includes a commented-out section for custom persistence using localStorage. ```javascript $"#jstree".jstree({ plugins: ["table"], core: { data: data }, table: { columns: [ {width: 200, header: "Name"}, {width: 150, value: "price", header: "Price"} ], resizable: true, stateful: true // Automatically save column widths to localStorage } }); // Handle column resize $"#jstree".on('resize_column.jstree-table', function(event, columnNumber, newWidth) { console.log('Column ' + columnNumber + ' resized to ' + newWidth + 'px'); // Custom persistence (if not using stateful option) // localStorage.setItem('col_' + columnNumber + '_width', newWidth); }); ``` -------------------------------- ### Integrate jsTree Table with Multiple Plugins (Checkbox, DnD) Source: https://context7.com/cuiyonghua/jstree-table/llms.txt Combine the table plugin with other jsTree plugins like checkbox, drag-and-drop (dnd), types, and context menu for rich functionality. This example demonstrates setting up these plugins and retrieving tree data as JSON. ```javascript $"#jstree".jstree({ plugins: ["table", "dnd", "types", "checkbox", "wholerow", "contextmenu"], "checkbox": { "three_state": false, "cascade": "down", "tie_selection": false, "whole_node": false }, 'table': { 'columns': [ {'header': 'Column 1'}, {'header': 'Column 2', 'value': 'col2'}, {'header': 'Column 3', 'value': 'col3'} ], 'resizable': true, 'contextmenu': true }, 'core': { "check_callback": true, 'data': [{"text": "Parent Node", "state": { "selected": true, "opened": true, "checked": false }, "parent": "#", "id": "node1", "data": { "col2": "Value 2", "col3": "Value 3" } }, {"text": "Child Node", "state": { "selected": true, "opened": true, "checked": true }, "parent": "node1", "id": "node2", "data": { "col2": "Child Value 2", "col3": "Child Value 3" } }] }, 'dnd': { "copy": false }, "types": { "#": { "max_children": 1 }, "default": { "valid_children": ["default"] } }, 'contextmenu': { 'items': {} } }); // Get tree data as JSON '$"#exportBtn"'.click(function() { var treeData = $"#jstree".jstree(true).get_json('#', { flat: true, no_state: false }); console.log(JSON.stringify(treeData)); }); ``` -------------------------------- ### jsTreeTable Resizable and Draggable Columns Source: https://context7.com/cuiyonghua/jstree-table/llms.txt Enables column resizing by dragging separators and column reordering via drag-and-drop. This functionality requires the jQuery UI sortable plugin. The example also shows enabling context menu for cell editing. ```javascript $("div#jstree").jstree({ plugins: ["table", "dnd", "contextmenu", "sort"], core: { data: data, check_callback: true }, table: { columns: [ {width: 200, header: "Name"}, {width: 150, value: "price", header: "Price", format: function(v) { if (v){ return '$'+v.toFixed(2) }}}, {width: 150, value: "quantity", header: "Qty"} ], resizable: true, // Enable column resizing draggable: true, // Enable column reordering (requires jQuery UI) contextmenu: true, // Enable right-click cell editing width: 500, height: 200 } }); ``` -------------------------------- ### Get jstree JSON Data (Left Tree) Source: https://github.com/cuiyonghua/jstree-table/blob/master/demo/dnd-test.html Attaches a click event handler to a button to retrieve the JSON representation of the jstree instance associated with the ID 'js1'. The 'get_json' method is used with options to flatten the tree and include state information. ```javascript $('#basbl').click(function() { var v = $("#js1").jstree(true).get_json('#', { flat: true, no_state: false }); var x = JSON.stringify(v); $("#testerl").text(x); return; }); ``` -------------------------------- ### Apply CSS Classes for Column Styling in jsTree Table Source: https://context7.com/cuiyonghua/jstree-table/llms.txt Apply custom CSS classes to headers, columns, and individual cells for flexible styling based on data values. This example shows how to use headerClass, columnClass, cellClass, wideCellClass, valueClass, and valueClassPrefix for dynamic styling. ```javascript $"#jstree".jstree({ plugins: ["table"], core: { data: data }, table: { columns: [ { width: 200, header: "Name", headerClass: "name-header", // CSS class for header cell columnClass: "name-column" // CSS class for entire column }, { width: 150, value: "price", header: "Price", cellClass: "price-cell", // CSS class for cell wideCellClass: "price-wide", // CSS class for cell
valueClass: "priceClass", // Node data attribute for dynamic class valueClassPrefix: "price-" // Prefix for valueClass }, { width: 150, value: "status", header: "Status", valueClass: "statusClass", // e.g., node.data.statusClass = "active" valueClassPrefix: "status-" // Results in class="status-active" } ] } }); // Example node data with dynamic classes var dataWithClasses = [{ id: "item1", text: "Item 1", data: { price: 10.99, status: "Active", priceClass: "high", // Will add class "price-high" statusClass: "active" // Will add class "status-active" } }]; ``` -------------------------------- ### Handle jstree Table Cell Selection Event (JavaScript) Source: https://context7.com/cuiyonghua/jstree-table/llms.txt This code demonstrates how to listen for the `select_cell.jstree-table` event. This event is triggered when a user clicks on a table cell, providing access to the cell's value, column information, and the associated tree node. It also includes an example of handling the `loaded_table.jstree` event. ```javascript $('#jstree').jstree({ plugins: ["table"], core: { data: data }, table: { columns: [ {width: 200, header: "Name"}, {width: 150, value: "price", header: "Price"} ] } }); // Handle cell click events $('#jstree').on('select_cell.jstree-table', function(event, data) { console.log('Cell clicked!'); console.log('Value:', data.value); // Cell value console.log('Column:', data.column); // Column header name console.log('Node:', data.node); // Reference to tree node element console.log('Source:', data.sourceName); // Data property name (e.g., "price") }); // Handle table loaded event $('#jstree').on('loaded_table.jstree', function() { console.log('Tree table finished loading'); }); ``` -------------------------------- ### Handle jstree Table Cell Update Event (JavaScript) Source: https://context7.com/cuiyonghua/jstree-table/llms.txt This example shows how to handle the `update_cell.jstree-table` event, which fires when a cell is edited via the context menu. It provides the node, column, new value, and old value, enabling actions like data validation or server-side persistence. The code also enables cell editing by setting `contextmenu: true`. ```javascript $('#jstree').jstree({ plugins: ["table"], core: { data: data, check_callback: true }, table: { columns: [ {width: 200, header: "Name"}, {width: 150, value: "price", header: "Price"} ], contextmenu: true // Enable cell editing via right-click } }); // Handle cell edit completion $('#jstree').on('update_cell.jstree-table', function(event, data) { console.log('Cell updated!'); console.log('Node:', data.node); // The edited node object console.log('Column:', data.col); // Column name (e.g., "price") console.log('New Value:', data.value); // New cell value console.log('Old Value:', data.old); // Previous cell value // Example: Save to server $.ajax({ url: '/api/update', method: 'POST', data: { nodeId: data.node.id, field: data.col, value: data.value } }); }); ``` -------------------------------- ### Initialize jstree-table with Data and Configuration Source: https://github.com/cuiyonghua/jstree-table/blob/master/demo/resize-event-test.html Initializes the jstree-table plugin with sample data and configuration options. It defines columns, their widths, headers, and data mapping. It also enables features like resizing and context menus. ```javascript $(document).ready(function(){ var data, trees, i, expected; data = [{ text: "Root 1", data: {price: "$5.00", size: "4",spanclass:"root"}, children: [ { text: "Really long named child whose name gets cut off", data: {price: "$4.00", size: "3",spanclass:"first"} }, { text: "Child 2", data: {price: "$3.00", size: "2",spanclass:"second"}, children:[ { text:"Grandchild", data:{price: "EXPENSIVE!",size:"10",spanclass:"third"} } ] } ] }]; $("#jstree").on("resize_column.jstree-table",function (e,column,width) { $("#colnum").text(column); $("#size").text(width); $("showevent").show(); }); $("#jstree").jstree({ htmlheader: 'Fixed Width, All Columns Defined, Columns < Width', plugins: ["themes","json","table"], core: { data: data }, table: { width: 400, columns: [ {width: 150, header: "Nodes",title:"_DATA_"}, {width: 100, cellClass: "col1", value: "price", header: "Price", title:"price", valueClass:"spanclass"}, {width: 75, cellClass: "col2", value: "size", header: "Qty", title:"size",valueClass:"spanclass"} ], resizable:true, contextmenu:true } }); }); ``` -------------------------------- ### jstree-table Initialization with Various Width Configurations Source: https://github.com/cuiyonghua/jstree-table/blob/master/demo/widths-test.html Initializes jstree-table instances with different width settings for the table and its columns. It demonstrates fixed pixel widths, percentage-based widths, and undefined widths. The code appends new tree sections to the DOM and sets up event listeners for the 'loaded_table.jstree' event to log actual rendered widths. ```javascript var trees = [ { htmlheader: 'Fixed Width, Columns Fixed', plugins: ["themes","json","table"], core: { data: data }, table: { width: 400, columns: [ {width: 150, header: "Nodes",title:"_DATA_"}, {width: 123, cellClass: "col1", value: "price", header: "Price", title:"price", valueClass:"spanclass"}, {width: "auto", cellClass: "col2", value: "size", header: "Qty", title:"size",valueClass:"spanclass"} ], resizable:true, contextmenu:true } }, { htmlheader: 'Undefined Width, One Column Undefined, Default Fixed', plugins: ["themes","json","table"], core: { data: data }, table: { columnWidth: 100, columns: [ {width: 150, header: "Nodes",title:"_DATA_"}, {width: 123, cellClass: "col1", value: "price", header: "Price", title:"price", valueClass:"spanclass"}, {cellClass: "col2", value: "size", header: "Qty", title:"size",valueClass:"spanclass"} ], resizable:true, contextmenu:true } }, { htmlheader: 'Undefined Width, One Column Undefined, Default Undefined', plugins: ["themes","json","table"], core: { data: data }, table: { columns: [ {width: 150, header: "Nodes",title:"_DATA_"}, {width: 123, cellClass: "col1", value: "price", header: "Price", title:"price", valueClass:"spanclass"}, {cellClass: "col2", value: "size", header: "Qty", title:"size",valueClass:"spanclass"} ], resizable:true, contextmenu:true } }, { htmlheader: 'Fixed Width, Columns Percentages', plugins: ["themes","json","table"], core: { data: data }, table: { width: 400, columns: [ {width: '35%', header: "Nodes",title:"_DATA_"}, {width: '45%', cellClass: "col1", value: "price", header: "Price", title:"price", valueClass:"spanclass"}, {width: '20%', cellClass: "col2", value: "size", header: "Qty", title:"size",valueClass:"spanclass"} ], resizable:true, contextmenu:true } }, { htmlheader: 'Undefined Width, Columns Percentages', plugins: ["themes","json","table"], core: { data: data }, table: { columns: [ {width: '35%', header: "Nodes",title:"_DATA_"}, {width: '45%', cellClass: "col1", value: "price", header: "Price", title:"price", valueClass:"spanclass"}, {width: '20%', cellClass: "col2", value: "size", header: "Qty", title:"size",valueClass:"spanclass"} ], resizable:true, contextmenu:true } } ]; for (i=0; i

'+trees[i].htmlheader+'

Expected '+expected+'


'); $("div#jstree"+i).on("loaded_table.jstree",function(){ var wrapper = $(this).closest("div.jstree-table-wrapper"), midw = wrapper.children("div.jstree-table-midwrapper"), section = wrapper.closest("div.treesection"), actuals = "Actuals "+wrapper.outerWidth()+": "+[midw.find("div.jstree-table-column:eq(0)").outerWidth(),midw.find("div.jstree-table-column:eq(1)").outerWidth(),midw.find("div.jstree-table-column:eq(2)").outerWidth()].join(' '); section.find(".actuals").text(actuals); }); $("div#jstree"+i).jstree(trees[i]); } }); ``` -------------------------------- ### Initialize jsTree with Table Plugin Source: https://github.com/cuiyonghua/jstree-table/blob/master/README.md This JavaScript code demonstrates how to initialize jsTree with the 'table' plugin enabled. It includes essential configurations like plugins, table-specific options, and core data. ```javascript $("div#id").jstree({ // include table as a plugin plugins: ["core","ui",...,"table"], // include relevant parameters table: { columns: [{},{},...,{}], width: 25 }, core: { data: [...] } }); ``` -------------------------------- ### Initialize jstree-table with Data and Configuration (JavaScript) Source: https://github.com/cuiyonghua/jstree-table/blob/master/demo/odd-named-id-test.html Initializes the jstree-table plugin with sample hierarchical data and configures table columns, including custom headers and data mapping. It also sets up event listeners for 'loaded_table.jstree', 'select_cell.jstree-table', and 'update_cell.jstree-table'. ```javascript $(document).ready(function(){ var data; data = [{ text: "Root 1", data: {price: "$5.00", size: "4",spanclass:"root"}, children: [ { id: "root 1/really long named child", text: "Really long named child whose name gets cut off", data: {price: "$4.00", size: "3",spanclass:"first"} }, { text: "Child 2", data: {price: "$3.00", size: "2",spanclass:"second"}, children:[ { text:"Grandchild", data:{price: "EXPENSIVE!",size:"10",spanclass:"third"} } ] } ] }]; $("div#jstree").bind("loaded_table.jstree",function(){ $("span#status").text("loaded"); }).on("select_cell.jstree-table",function (e,data) { $("span#clicked").html("clicked "+data.column+" of value "+data.value); }).on('update_cell.jstree-table',function (e,data) { $("span#changed").html("changed "+data.col+" from "+data.old+" to "+data.value); }); $("div#jstree").jstree({ plugins: ["themes","json","table"], core: { data: data }, table: { columns: [ {width: 110, header: "Nodes",title:"_DATA_"}, {cellClass: "col1", value: "price", header: "Price", title:"price", valueClass:"spanclass"}, {cellClass: "col2", value: "size", header: "Qty", title:"size",valueClass:"spanclass"} ], resizable: true, contextmenu: true } }); }); ``` -------------------------------- ### Initialize jstree Treetable with Data and Search (JavaScript) Source: https://github.com/cuiyonghua/jstree-table/blob/master/demo/search-test.html Initializes the jstree with the 'table' plugin, providing sample data and configuring columns for display. It also sets up a search input to filter tree nodes dynamically. Dependencies include the jstree library and its 'table' plugin. ```javascript $(document).ready(function(){ var data = [ { "id" : "Root", "parent" : "#", "text" : "Root"}, { "id" : "child1", "parent" : "Root", "text" : "child1", "data" : { "open" : "2/5/2015 2:18:00 PM", "close" : "2/6/2015 10:16:00 AM", "status" : "Closed"}}, { "id" : "child1-1", "parent" : "child1", "text" : "child1-1", "data" : { "open" : "2/5/2015 2:18:00 PM", "close" : "2/6/2015 10:16:00 AM", "status" : "Closed"}}, { "id" : "child2-2", "parent" : "child1", "text" : "child2-2", "data" : { "open" : "2/5/2015 2:18:00 PM", "close" : "2/6/2015 10:16:00 AM", "status" : "Closed"}}, { "id" : "child2", "parent" : "Root", "text" : "child2", "data" : { "open" : "2/5/2015 2:18:00 PM", "close" : "2/6/2015 10:16:00 AM", "status" : "Closed"}}, { "id" : "child3", "parent" : "Root", "text" : "child3", "data" : { "open" : "2/5/2015 2:18:00 PM", "close" : "2/6/2015 10:16:00 AM", "status" : "Closed"}} ] $('#jstree').jstree({ "core" : { "data" : data }, "plugins" : [ "checkbox", "search", "table" ], "search" : { "show_only_matches" : false}, "table" : { columns: [ {width: 190, header: "name"}, {width: 140, header: "open", value: "open"}, {width: 140, header: "close", value: "close"}, {width: 130, header: "status", value: "status"} ] } }); var to = false; $('#treeSearch').keyup(function () { if(to) { clearTimeout(to); } to = setTimeout(function () { var v = $('#treeSearch').val(); $('#jstree').jstree(true).search(v); }, 250); }); }); ``` -------------------------------- ### Initialize jstree with Table Plugin and JSON Data Source: https://github.com/cuiyonghua/jstree-table/blob/master/demo/fnvalue-test.html Initializes a jstree instance with the 'table' plugin, using provided JSON data to populate the tree structure. It configures core jstree settings, checkbox behavior, and specific table column definitions, including custom value renderers for price inputs. ```javascript $(document).ready(function(){ // $( ".stopclick" ).on('click',function( event ) { $( "#wrapper" ).on('click','.stopclick',function( event ) { if (event.preventDefault) { event.preventDefault(); } if (event.stopPropagation) { event.stopPropagation(); } if (event.stopImmediatePropagation) { event.stopImmediatePropagation(); } }); var jsonData = [ { "id": 1, "text": "Materials and varieties", "parent": "#", "data": { "item_id": 1, "mal_item_name": null, "data_needed": "N", "def_unit_id": null, "col_unit_id": null, "shop1_price": null, "shop2_price": null, "remarks": null } }, { "id": 2, "text": "Bricks", "parent": "1", "data": { "item_id": 2, "mal_item_name": null, "data_needed": "N", "def_unit_id": null, "col_unit_id": null, "shop1_price": null, "shop2_price": null, "remarks": null } }, { "id": 3, "text": "Class(Country burnt)(8\" 4\" 4\")(high quality)", "parent": "2", "data": { "item_id": 3, "mal_item_name": null, "data_needed": "Y", "def_unit_id": 9, "col_unit_id": null, "shop1_price": null, "shop2_price": null, "remarks": null } }, { "id": 4, "text": "Class(Country burnt)(8\" 4\" 4\")(low quality)", "parent": "2", "data": { "item_id": 4, "mal_item_name": null, "data_needed": "Y", "def_unit_id": 9, "col_unit_id": null, "shop1_price": null, "shop2_price": null, "remarks": null } }, { "id": 11, "text": "River Sand", "parent": "1", "data": { "item_id": 11, "mal_item_name": null, "data_needed": "N", "def_unit_id": null, "col_unit_id": null, "shop1_price": null, "shop2_price": null, "remarks": null } }, { "id": 12, "text": "Coarse", "parent": "11", "data": { "item_id": 12, "mal_item_name": null, "data_needed": "Y", "def_unit_id": 10, "col_unit_id": null, "shop1_price": null, "shop2_price": null, "remarks": null } } ]; $('#treeViewDiv').jstree({ "core": { "animation": 0, "check_callback": true, "themes": { "name": false, //default theme used "stripes": true, "variant": "large", "theme": "default", "dots": true, "icons": true, "url": false, // url of theme's css file "expand_selected_onload": true, }, "data": jsonData }, "checkbox": { "keep_selected_style": false, "three_state":false, "two_state": true, "whole_node": true }, "table": { "columns": [ { width: 350, header: "Items", headerClass: "jtreeHeader", wideCellClass: "jtreeCell", title: "_DATA_" }, { width: 120, header: "Shop1 Price", headerClass: "jtreeHeader", wideCellClass: "jtreeCell", title: "Price from Shop1", value: function (node) { if (node.data.data_needed == 'Y') { return (''); } } }, { width: 120, header: "Shop2 Price", headerClass: "jtreeHeader", wideCellClass: "jtreeCell", title: "Price from Shop2", value: "ABC" }, { width: 120, header: "Shop1 Price", headerClass: "jtreeHeader", wideCellClass: "jtreeCell", title: "Price from Shop1", value: function (node) { if (node.data.data_needed == 'Y') { return (''); } } } ], "contextmenu": true, "resizable": true }, "plugins": ["checkbox", "contextmenu", "dnd", "search", "state", "types", "table", "wholerow"] }); }); ``` -------------------------------- ### Get jstree JSON Data (Right Tree) Source: https://github.com/cuiyonghua/jstree-table/blob/master/demo/dnd-test.html Attaches a click event handler to a button to retrieve the JSON representation of the jstree instance associated with the ID 'js2'. This function is similar to the left tree's JSON retrieval but operates on the second jstree instance. ```javascript $('#basbr').click(function() { var v = $("#js2").jstree(true).get_json('#', { flat: true, no_state: false }); var x = JSON.stringify(v); $("#testerr").text(x); return; }); ``` -------------------------------- ### Initialize jstree-table with Data and Configuration Source: https://github.com/cuiyonghua/jstree-table/blob/master/demo/click-sort-test.html Initializes a jstree-table instance with sample hierarchical data, defining columns, and enabling features like resizing, context menus, and drag-and-drop. The data includes text and custom data objects for price, size, and span class. ```javascript $(document).ready(function(){ var data; data = [ { text: "Root 1", data: {price: "$5.00", size: "4",spanclass:"root"}, children: [ { text: "Really long named child whose name gets cut off", data: {price: "$4.00", size: "3",spanclass:"first"} }, { text: "Child 2", data: {price: "$8.00", size: "2",spanclass:"second"}, children:[ { text:"Grandchild", data:{price: "EXPENSIVE!",size:"10",spanclass:"third"} } ] } ] } ]; $("div#jstree").jstree({ plugins: ["themes","json","table","dnd","contextmenu","search","sort"], core: { data: data }, table: { columns: [ {width: 110, header: "Nodes",title:"_DATA_"}, {cellClass: "col1", value: "price", header: "Price", title:"price", valueClass:"spanclass"}, {cellClass: "col2", value: "size", header: "Qty", title:"size",valueClass:"spanclass"} ], resizable: true, contextmenu: true }, dnd: { drop_finish : function () {}, drag_finish : function () {}, drag_check : function (data) { return { after : true, before : true, inside : true }; } } }); }); ```