Check documentation for the latest version of dhtmlxSuite beforeUpdate DHTMLX Docs

beforeUpdate

This event occurs before updating values in database and can cancel default update statement (see error, invalid and success methods below). It can be used also to validate incoming values (see invalid() method below).

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

Samples of usage:

//creates and runs own update statement using values came in request, cancels default 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));
//checks if value of name is empty, then cancel update. Otherwise proceeds with default update.  
class CustomBehavior extends ConnectorBehavior{
    @Override 
    public void beforeUpdate(DataAction data) {
        if (data.get_value("name").equals(""))
             data.invalid();
    } 
}
component.event.attach(new CustomBehavior());
//sets new value for name and proceeds with default update. 
class CustomBehavior extends ConnectorBehavior{
    @Override 
    public void beforeUpdate(DataAction data) {
         data.set_value("name","some new value");
    } 
}
component.event.attach(new CustomBehavior());
Back to top