Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by gmro on Nov 13, 2009 16:21
open dhtmlx forum
gmro

I have a html table in a page and I want to transform it into a dhtmlxgrid, with custom attributes.

So i took the exaple from this site (http://www.dhtmlx.com/docs/products/dhtmlxGrid/samples/12_initialization_loading/03_grid_int_from_html.html):

<!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/dhtmlxgrid.css">
    <link rel="stylesheet" type="text/css" href="codebase/skins/dhtmlxgrid_dhx_skyblue.css">
    <script src="codebase/dhtmlxcommon.js"></script>
    <script src="codebase/dhtmlxgrid.js"></script>
    <script src="codebase/dhtmlxgridcell.js"></script>
    <script src="codebase/ext/dhtmlxgrid_start.js"></script>
    <script>dhtmlx.skin = "dhx_skyblue";</script>
</script>
</head>

<body>
<table class="dhtmlxGrid" name="grid2" imgpath="codebase/imgs/" style="width:400px">
<tr>
<td>value 11</td>
<td>12</td>
</tr>
<tr>
<td>value 21</td>
<td>22</td>
</tr>
<tr>
<td>value 31</td>
<td>32</td>
</tr>
<tr>
<td>value 41</td>
<td>42</td>
</tr>
<tr>
<td>value 51</td>
<td>52</td>
</tr>
</table>
</body>
</html>

What I want now is to set attributes to this grid, like the ones that can be set to an xml-loaded grid. For example:
mygrid.setHeader("Sales, Book Title, Author");
mygrid.setInitWidths("100,250,*");
mygrid.setColAlign("right,left");
mygrid.setColTypes("ed,ed,ed");

How can I do that?

What I've tried is something I found as example on a site: I added two functions in the <head> section of the html file and I put them in the <table> tag, so now my html file looks loke this:

<!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/dhtmlxgrid.css">
    <link rel="stylesheet" type="text/css" href="codebase/skins/dhtmlxgrid_dhx_skyblue.css">
    <script src="codebase/dhtmlxcommon.js"></script>
    <script src="codebase/dhtmlxgrid.js"></script>
    <script src="codebase/dhtmlxgridcell.js"></script>
    <script src="codebase/ext/dhtmlxgrid_start.js"></script>
    <script>dhtmlx.skin = "dhx_skyblue";</script>

     <script>
     function myfunc1(){
     grid2.enableMultiselect(true);
         grid2.setHeader("Col_1","Col_2");
     }
    function myfunc2(){
     grid2.selectRow(2);
          grid2.setColTypes("ed,ro");    
         grid2.setColAlign("right,right");
     }
</script>
</head>

<body>
<table class="dhtmlxGrid" name="grid2" imgpath="codebase/imgs/" style="width:400px" onbeforeinit="myfunc1()" oninit="myfunc2()">
<tr>
<td>value 11</td>
<td>12</td>
</tr>
<tr>
<td>value 21</td>
<td>22</td>
</tr>
<tr>
<td>value 31</td>
<td>32</td>
</tr>
<tr>
<td>value 41</td>
<td>42</td>
</tr>
<tr>
<td>value 51</td>
<td>52</td>
</tr>
</table>
</body>
</html>

But this doesn't solve the problem. The situation is like this:
- the Multiselect (from myfunc1) is enabled - this attribute works
- the header (from myfunc1) is NOT Col_1, Col_2 - this attribute does NOT work: on the first row (formated as a header) I have the ('value 11', 12) row

- the selectRow(2) (from myfunc2) works: the row ('line 41',42) is selected
- the setColTypes (from myfunc2) works
- the setColAlign (from myfunc2) does NOT work: both columns are left-aligned

Please tell me what am I doing wrong, why some attributes do not work. Or if you have a better approach to my needs, please tell me how should I set the dhtmlxgrid attributes to an existing html table.

Thank you!

Answer posted by dhxSupport on Nov 16, 2009 07:47