Check documentation for the latest version of dhtmlxSuite Making Queries DHTMLX Docs

Making Queries

Simple queries

Applicable: Grid, TreeGrid, Tree, Combo, Scheduler

By default, the connector generates all INSERT/UPDATE/DELETE queries automatically, based on configuration.

For more details of this topic, see the Basic Loading chapter.

In case of dnd, connector will process an action as a sequence of 'insert' and 'delete' operations.

Complex queries

When you need to define your own logic you should use one of two ways:

Custom queries for an action

Applicable to: Grid, TreeGrid, Tree, Combo, Scheduler

You can define your own SQL code for a specific action (INSERT, UPDATE or DELETE) as follows:

gridConn.sql.attach(OperationType.UPDATE,"Update tableA set name='{name}', price={price} where id={id}");
//...
gridConn.render_sql(" .. ","id","price,name");

Parameters:

  • an action's name. Possible values are: 'Update', 'Insert', 'Delete'
  • SQL statement. It can use fields(or their aliases) which were mentioned in the render_sql or render_table method while loading data.

Using server-side events

Applicable to: Grid, TreeGrid, Tree, Combo, Scheduler

To customize operations you can use the following server-side events:

//data preprocessing before update
class updateBehavior extends ConnectorBehavior{
        @Override
    public void beforeUpdate(DataAction action) {
      String price = data.get_value("price");
      data.set_value("price","$"+price); //modifies data before saving in DB
    }
}
conn.event.attach(new updateBehavior());


//including additional field to request
class updateBehavior extends ConnectorBehavior{
        @Override
    public void beforeInsert(DataAction action) {
          //include additional data in DB operation
          data.add_field("userId",1); //will be saved as part of new record
    }
}
conn.event.attach(new updateBehavior());


//fully custom code
class updateBehavior extends ConnectorBehavior{
        private GridConnector conn;
        public updateBehavior(GridConnector conn){
            this.conn = conn;
        }
 
        @Override
    public void beforeUpdate(DataAction action) {
        String price = data.get_value("price");
        String id = data.get_value("id");
        DBDataWrapper db = (DBDataWrapper)conn.sql;
        db.query("UPDATE some_table SET price='"+price+"' where id="+id);
        data.success(); //if you have made custom update - mark operation as finished
    }
}
conn.event.attach(new updateBehavior(conn));
Back to top