Skip to main content

Initialization

info

Download the DHTMLX TreeGrid package:

To initialize DHTMLX TreeGrid on a page, you need to take the following simple steps:

index.html
<!DOCTYPE html>
<html>
<head>
<title>How to Start with DHTMLX TreeGrid</title>
<script type="text/javascript" src="../../codebase/treegrid.js"></script>
<link rel="stylesheet" href="../../codebase/treegrid.css">
</head>
<body>
<div id="treegrid_container" style="height: 100%; width: 100%"></div>
<script>
// creating DHTMLX TreeGrid
const treegrid = new dhx.TreeGrid("treegrid_container", {
columns: [
{ width: 100, id: "a", header: [{ text: "#" }] },
{ width: 100, id: "b", header: [{ text: "Title" }] },
{ width: 200, id: "c", header: [{ text: "Name" }] },
{ width: 200, id: "d", header: [{ text: "Address" }] }
],
headerRowHeight: 50,
data: dataset
});
</script>
</body>
</html>

Include source files

Unpack the downloaded package into a folder of your project.

After that, create an HTML file and place full paths to JS and CSS files of DHTMLX TreeGrid into the header of the created file. The TreeGrid component can be used standalone or as a part of the Suite library.

If you use DHTMLX TreeGrid standalone, you need to include 2 files:

  • treegrid.js
  • treegrid.css
<script type="text/javascript" src="../../codebase/treegrid.js"></script>
<link rel="stylesheet" href="../../codebase/treegrid.css">

If you use DHTMLX TreeGrid as a part of the Suite package, you need to include JS/CSS files of the dhtmlxSuite library:

  • suite.js
  • suite.css
<link type="text/css" href="../codebase/suite.css">
<script src="../codebase/suite.js" type="text/javascript"></script>

Create a container

Add a container for TreeGrid and give it an id, for example "treegrid_container". To display TreeGrid on the page correctly, define width and height of the container.

index.html
<div id="treegrid_container" style="width:800px; height:600px"></div>

Initialize TreeGrid

Initialize TreeGrid with the dhx.TreeGrid object constructor. The constructor has two parameters:

  • the HTML container for TreeGrid,
  • optional, an object with configuration properties. If this argument is not passed to the constructor, the settings will be default.
index.js
// creating DHTMLX TreeGrid
const treegrid = new dhx.TreeGrid("treegrid_container", {
columns: [
{ width: 100, id: "a", header: [{ text: "#" }] },
{ width: 100, id: "b", header: [{ text: "Title" }] },
{ width: 200, id: "c", header: [{ text: "Name" }] },
{ width: 200, id: "d", header: [{ text: "Address" }] }
],
headerRowHeight: 50,
data: dataset
});

Configuration properties

There is a set of properties you can specify for TreeGrid to optimize its configuration for your needs.

See the detailed information on configuration properties of TreeGrid in the TreeGrid API overview article.

Load data into TreeGrid

Detailed information on loading data into TreeGrid is given in the Data loading article.

Example