Check documentation for the latest version of dhtmlxSuite General HowTos DHTMLX Docs

General HowTos

How can I assign aliases to DB columns?

By using the render_sql() or render_table() methods you can assign aliases to the required tables or columns. For this purpose, in sql statement you should use word 'as' (as in any usual sql statement), in other parameters - parentheses.

grid.render_table("tableA","id","name,price(product_price)");
//or
grid.render_sql(
    "Select *,tableA.id as aid from tableA, tableB  where  tableA.id=tableB.id", 
    "tableA.id(aid)",
    "name,price(product_price),other"
);

How can I attach event?

To attach event you should use component.event.attach(). For more details on this topic, see the 'Handling Events' guide.

class CustomBehavior extends ConnectorBehavior{
        @Override 
    public void beforeUpdate(DataAction data) {
        //any custom code
    } 
}
component.event.attach(new CustomBehavior());

How can I check the value of an item?

With the help of the get_value() method you can check the value of any item.

grid.get_value(name);

How can I deny access to a certain operation?

By default, the connector allows all operations. To deny some operation use the deny(name_of_operation) method that can get one of the following params:read/update/insert/delete. For more details see the 'Security' guide.

grid.access.deny(OperationType.Read);

How can I customize the content of a cell?

You can use the beforeRender event to define how the content of a cell must be formatted.

class RenderBehavior extends ConnectorBehavior{
    public void beforeRender(DataItem data) {
        String field = data.get_value("some");
        data.set_value("some","<a href='details.php?id="+field+"'>"+Details+"</a>");
    } 
}
 
grid = new GridConnector(res);
grid.event.attach(new RenderBehavior());

In the sample above, the grid will have a custom content.

How can I filter data on the server side?

You have 2 ways to filter data on the server backend:

  • by using in-header filter types during the component configuration (on the client side)
mygrid.setHeader("Column A, Column B");
mygrid.attachHeader("#connector_text_filter,#connector_select_filter");
class FilterBehavior extends ConnectorBehavior{
    @Overrride
    public void beforeRender(DataItem data){
        if (data.get_value("some") < 0 )
        data.skip();
    }
}
conn.attach.event(new FilterBehavior());

See the guide 'Filtration' for more information.

How can I handle errors and log them?

You can enable logging using the enable_log() method. For more details see the 'Error handling and logging' guide.

gridConn.enable_log("path");//to show short info on the client side
//or
gridConn.enable_log("path",true);// to show full info on the client side

How can I set a value to an item?

By means of using the set_value() method, you can set a value to any item of component.

dataItem.set_value(name,value)

How can I sort data on the server side?

You have 2 ways to sort data on the server backend:

  • by specifying additional parameters in URL (on the client side)
grid.load("some.php?connector=true&dhx_sort[2]=asc");
  • by using the sorting type 'connector' during the component configuration (on the client side)
grid.setColSorting("connector,str,na);

See the guide 'Sorting' for more information.

How can I validate data on the client side?

dataProcessor lets you validate data on the client side. Use the setVerificator(index,method) method to define the appropriate columns and validators. See details in the related chapter of dataProcessor' documentation.

dp.setVerificator(column_index,verification_func)

How can I validate data on the server side?

To perform server-side validation you should use one of the dhtmlxConnector events stated below and specify the needed validation rules in the appropriate events' handlers functions:

class validateBehavior extends ConnectorBehavior{
    ...
}
 
conn.event.attach(new validateBehavior());

For more details on the server-side validation, see the 'Validation' guide.

Back to top