There are two ways to place grid on the page, but as the main goal of this article is to show you the simplicity of dhtmlx components' usage, I'll go the most common way. So I need to place DIV on my page and set ID attribute to some unique value. Also I'll specify the grid's width and height right in the style attribute of the DIV.
<div id="mygrid_container" style="width:600px;height:150px;"></div>
Now I proceed to the main phase of the process - defining the grid parameters. So in the script block (remember? I left it empty right after external javascript files inclusions) I write the following:
var mygrid; function doInitGrid(){ }
doInitGrid function will contain grid initialization code (not so much code I would say):
mygrid = new dhtmlXGridObject('mygrid_container'); mygrid.setImagePath("codebase/imgs/"); mygrid.setHeader("Model,Qty,Price"); mygrid.setInitWidths("*,150,150"); mygrid.setColAlign("left,right,right"); mygrid.setSkin("light"); mygrid.init();
Now we need to run this function. It is important to run it after DIV element that we would use for grid iniialization was loaded. So I could place this function call in the script block right after the mentioned DIV, but I prefer to use onload event of the “body: element for this. So my “body” tag will look like this:
<body onload="doInitGrid();">
If you run the page now it should look like this: