Loading Additional Data to Grid

To load additional data to the grid you can use:

  • Hidden Columns.
  • Userdata.
  • Custom attributes.

Hidden Columns

To make some extra data in the grid invisible, you can hide some column(s). So, the data in such column(s) will be invisible to users but accessible by API.

To hide a column, use the setColumnHidden method:

mygrid = new dhtmlXGridObject('gridbox');  
mygrid.setHeader("Name, Email, Age"); 
grid.setColumnHidden(0,true); //hides the 1st column

Related sample:  Hide/Show column

The data from hidden columns can be accessed in a usual way:

var value = grid.cells("row1",0).getValue();

In case of initialization from XML, a column can be hidden as in:

        <column hidden="true">Dummy</column>     </head>

By default, data of hidden columns is included into serialization and can't be controlled by the setSerializableColumns method. Also, the data of hidden columns is available during dataProcessor calls.


To add a userdata to the whole grid or some of its rows, use the setUserData method:

//adds userdata to the row with id="row1"
var userdata = mygrid.getUserData("row1","priority");//-> "high"
//adds userdata to the whole grid
var userdata = mygrid.getUserData("","priority");//-> "high"

Related sample:  Using Grid API Methods

In case of initialization from XML, you can use a special tag - <userdata></userdata>:

  <userdata name="somName1">some data</userdata>   //userdata related to the whole grid
    <row id="unique_rowid"> 
      <userdata name="someName1"> some row data </userdata> //userdata related to a row
      <userdata name="someName2"> some row data </userdata>
      <cell>cell content</cell>
      <cell><![CDATA[<font color="red">cell</font> content]]></cell>

Custom attributes

To add a custom attribute to a row in the grid, use the setRowAttribute method:

var value = mygrid.getRowAttribute("row1","priority"); //->"high"

To add a custom attribute to a cell in the grid, use the setAttribute method:

var value = mygrid.cells("row1",0).getAttribute("priority"); //->"high"

In case of initialization from XML, you can use a special tag - <row></row>:

    <row id="unique_rowid" priority="high">         <cell some="data">cell content</cell>

By default, custom attributes are not included into serialization and not available during dataProcessor calls.

In case of initialization from XML you can include a custom attribute into serialization as in:

mygrid.xml.row_attrs.push("priority");  //includes some row attribute into serialization
mygrid.xml.cell_attrs.push("priority"); //includes a cell attribute into serialization

Related sample:  Setting custom attributes

Back to top