Before working with library, scavenging information from the documentation, checking examples and making up conclusions - consolatory or not – you should read this article. It will take less than 10 minutes, but will save considerably more of your time in the near future. This article is aimed to explain the working logic of library and to provide the basic code examples. In case you intend to go deep into the matter and jump to creating applications you can be sure this article meets your needs. Well, let’s come down to practice:
Dhtmlx library consists of different components, which can be used separately – for example, you are allowed to insert grid into your application for data output in table mode, tree and menu – for navigation purposes. As well, you can use the entire library to get necessary functionality and structure interface.
To start working with library you should download dhtmlxSuitehere. Package contains 15 (or 16 for professional edition) components. All components are listed on download page.
Package content:
When you unpack the entire archive you will find index.html file (see point 4 in the paragraph above) and only after starting this file you will be able to see all components documentation. Thus, the archive file doesn't contain documentation. It is distributed within component folders, if you need to have access to all documentation files you can find it in dhtmlx Docs and Samples Explorer. By the way, you can avoid unpacking procedure and local working, there is an opportunity to check documentation on our site, all necessary documentation and samples are here: http://dhtmlx.com/docs/products/docsExplorer/index.shtml
To start working immediately, you should unpack dhtmlx_std_full.zip (dhtmlx_pro_full.zip) archive in the place from where you are going to load scripts (Note: the folder must be available through web-server, otherwise some functionality will not be able to work). In any case, you are creating a web-application, so a web-server involvement is mandatory.
Except script file, archive contains styles file and all necessary images. So, let's unpack it in /codebase for example. The structure looks approximately as follows:
[codebase] [imgs] dhtmlx.js dhtmlx.css index.html
The last file indicates where we will create the interface of the application and make it work.
Don't be confused with the size of the script file - 900 Kbytes. First, it contains the entire functionality, including specific one. When it comes to your application release, you will be able to leave just necessary functionality using the attached tool (see point 2). Secondly, all modern browsers support operating with the packed scripts, as for gzip format, here the maximum bundling weighs less than 200 Kbyts, so, browser successfully caches it as well as external content.
Also, you can use files only with necessary functionality. But in this case it's required permanent synchronization with documentation (to know which file has to be pasted to make work certain functionality). For more details about files required for component initialization and functionality support (extensions usage), see separate components documentation.
Let's return to index.html file.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <head> <title>My Application</title> <link rel="STYLESHEET" type="text/css" href="codebase/dhtmlx.css"> <script src="codebase/dhtmlx.js" type="text/javascript"></script> <script> function buildInterface(){ //entire code for interface init will go here } dhtmlxEvent(window,"load", buildInterface); </script> </head> <body> </body> </html>
The main conclusion you should make up is that interface creation has to be started from the full page loading. Why do we use dhtmlxEvent? Because it makes event setting available for any browser.
<div id="mygrid"></div> <script> myGrid = new dhtmlXGridObject("mygrid"); </script>
myLayout = new dhtmlXLayout(document.body,"3E"); myGrid = myLayout.items(0).attachGrid();
For more details about allocating dhtmlx and other items inside Layout, Tabbar and Window, see here.
There are three ways to initialize any component of the suite:
myWindows = new dhtmlxWindows();
myGrid = new dhtmlXGridObject("grid_container"); myGrid.setImagePath("codebase/imgs/"); myGrid.setHeader("Model,Qty,Price"); myGrid.setInitWidths("*,150,150"); myGrid.setColAlign("left,right,right"); myGrid.setSkin("light"); myGrid.init(); myGrid.loadXML("some_url.php");
myGrid = new dhtmlXGridObject({ parent: "grid_container", image_path: "codebase/imgs/", skin: "light", columns: [ { label: "Model", width: "*", align: "left", },{ label: "Qty", width: 150, align: "right", },{ label: "Price", width: 150, align: "right", } ] }); myGrid.loadXML("some_url.php");
There are some parameters which can be set for all components on page at once. Currently they are: skin name and path to images.
If these parameters are set for concrete objects later, they will have priority status.
attachEvent(event_name,handler_function) allows to set event handlers for any components of dhtmlxSuite. For lists of events see Script API Reference partition, which is located at the foot of generic page of any component documentation. Note: names of events are case-insensitive.
Nearly every event passes to function-handler some parameters which can be used in this function. Such parameters are listed in documentation. This is an example:
myGrid.attachEvent("onRowSelect",function(rowId,cellInd){ alert("Row was selected. It's id is "+ rowId +". Index of clicked cell is "+ cellInd) });
There is the main approach to interface creation by using dhtmlx library capabilities:
myLayout1 = new dhtmlxLayout({ parent:document.body; schema: "3J"; }) myLayout1.cells("c").hideHeader(); myLayout2 = new dhtmlxLayout({ parent: myLayout1.cells("c"), schema: "3E" })
Here we get the sum of 2 layouts and 5 cells (2 cells are taken from the first layout, 3 others - from the second one) for items placement. You should call them accordingly to the following logic:
myLayout1.cells(“a”), myLayout1.cells(“b”), myLayout2.cells(“a”), myLayout2.cells(“b”),myLayout2.cells(“c”).
After initializing components, properties of them (to be more precise, most of them) can be changed dynamically - by using API methods. Generally, such methods start with set or enable. To call subobjects (rows and columns in grid, item in tree, windows in window system, cells in layout, buttons in toolbar, items in menu etc) you should use ID. Besides correcting properties through API, you are allowed to achieve any desired functionality of components. For more information see Documentation (search is enabled) orKnowlege Base, or contact our support team.