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.
When you need to define your own logic you should use one of two ways:
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:
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