By default connector generates all create|update|delete queries automatically, based on configuration. But in some cases it may be necessary to define your own logic. It can be done in one of two ways
You can define your own SQL for 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");
The parameters are the following:
Grid provides set of events, which can be used to handle server side action in your custom way
class updateBehavior extends ConnectorBehavior{ @Override public void beforeUpdate(DataAction action) { String price = data.get_value("price"); data.set_value("price","$"+price); //modify data before saving in DB } @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 update 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"); conn.sql.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));