DHTMLX Docs & Samples Explorer

Storing Additional Data

There are three possible approaches to load additional data:

  • Hidden Columns;
  • UserData;
  • Attributes.

Hidden Columns

It is possible to define a column as hidden - in such case, it will not be visible for a user, but it will be accessible by API. So it will be possible to take the data from it.

In case of initialization from JS code, the user should write the following:

        //...
        grid.init();
        grid.setColumnHidden(index,true); // indicate column index and set the state to true to hire the column

In case of initialization from XML, the syntax will be like this:

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

The data can be accessed as data of any other columns:

        grid.cells(i,j).getValue();
        grid.cells(i,j).setValue(some);

Data of a hidden column is included in the serialization by default, and can't be controlled by setSerializableColumns() command. This data is available during dataprocessor calls

UserData

UserData is a special tag that can be:

  • child of <rows> - userdata is related to the whole grid;
  • <row> tags - userdata is related to a specific row.

UserData can be set in XML in the following way:

    <?xml version='1.0' encoding='iso-8859-1'?>
        <rows>
            <userdata name="somName1">some data</userdata>
            <row id="unique_rowid">
                    <userdata name="someName1"> some row data </userdata>
                    <userdata name="someName2"> some row data </userdata>
                    <cell>cell content</cell>
                    <cell><![CDATA[<font color="red">cell</font> content]]></cell>
            </row>
        </rows>

Accessing Global UserData

The following methods are used for this purpose:

        var userdata = grid.getUserData("","someName1");  // some data
        grid.setUserData("","someName1","new value");

The following methods are used in the code sample above:

  • getUserData(row_id, name) - this method gets user data; the parameters that should be indicated are:
    • row_id - id of the row; if it is set as an empty string, user data is for the grid (not a row);
    • name - name of user data.
  • setUserData(row_id, name, value) - sets user data to a row with the following parameters:
    • row_id - id of the row, if it is set as an empty string, user data is set for the grid (not a row);
    • name - name of user data block;
    • value - value of user data block.

Accessing Row-Related UserData

Row-related UserData can be accessed like this:

        var userdata = grid.getUserData("unique_rowid","someName1");                 // some row data
        grid.setUserData("unique_rowid","someName1","new value");

UserData may be included in the serialization process using setSerializationLevel() command (it is disabled by default).

This data is available during dataprocessor calls.

Attributes

dhtmlxgrid 1.6+ allows accessing any attribute of row or cell tag programmatically when loading from XML:

    <?xml version='1.0' encoding='iso-8859-1'?>
        <rows>
            <row id="unique_rowid" some="data">
                    <cell some="data">cell content</cell>
            </row>
        </rows>

Accessing Row Attributes

The following methods are used to access row attributes:

        var rowAttr = grid.getRowAttribute("unique_rowid","some");
        grid.setRowAttribute("unique_rowid","some","new value");

Accessing Cell Attributes

To access cell attributes, the following code lines should be used:

        grid.cells(i,j).getAttribute("some");
        grid.cells(i,j).setAttribute("some","new value");

Including Attributes in Serialization

If the user wants to include such custom attributes in the serialization, some special steps are required:

            grid.xml.row_attrs.push("some");    // will include some attribute of a row in the serialization
            grid.xml.cell_attrs.push("some");    // will include some attribute of a cell in the serialization

Note: This data is not available during dataprocessor calls.