Check documentation for the latest version of dhtmlxSuite Grid Specific HowTos DHTMLX Docs

Grid Specific HowTos

How can I define grid structure on the server side?

To define grid structure on the server side you can choose one of two ways:

  • define the configuration in the constructor;
  • create an empty object and then specify its configuration through the related methods.

The first case:

GridColumn column1 = new GridColumn(
    String header, 
    String type, 
    String id, 
    int width,
    String align, 
    String valign, 
    String sort, 
    String color, 
    Boolean hidden
);
GridColumn column2 = ...
 
GridConfiguration myConfig= new GridConfiguration();
myConfig.addColumn(column1);
myConfig.addColumn(column2);

The second case:

GridColumn column1 = new GridColumn();
GridColumn column2 = ...
 
column1.setHeader("Column1");
column1.setType("ed");
...
GridConfiguration myConfig= new GridConfiguration();
myConfig.addColumn(column1);
myConfig.addColumn(column2);

How can I load data from a table that doesn't contain the identity field?

By using KeyGridConnector instead of GridConnector, you can load data from a table without identity field. In this case, any data field will serve as the identity one.

Connection conn = ( new DataBaseConnection()).getConnection();
KeyGridConnector data = new KeyGridConnector(conn);
data.render_table("mytable","name","name,address,phone");

For more details, see the 'KeyGridConnector' guide.

How can I set a custom style for a row or a cell?

dhtmlxConnector contains a bit of methods that allow setting the appearance of a grid.

These methods can be divided into 2 groups:

for a cell customization:

  • set_cell_attribute
  • set_cell_class
  • set_cell_style

for a row customization:

  • set_row_attribute
  • set_row_color
  • set_row_style
class RenderBehavior extends ConnectorBehavior{
    public void beforeRender(DataItem data) {
        if (data->get_index() % 2 == 1 )
        data.set_row_color("red");
    } 
}
Connection res = ( new DataBaseConnection()).getConnection();
GridConnector grid = new GridConnector(res);
grid.event.attach(new RenderBehavior());
grid.render_table("grid50000","item_id","item_nm,item_cd");

Tips:

  • to overwrite the background you should use the 'background' attribute, not the 'background-color' one.
  • skin's css can overwrite a number of css attributes. To avoid it, use the !important flag.
data.set_row_attribute("class","backrgroundclass");


.backrgroundclass{
   background:red !important;
}
Back to top