APPLICABLE TO: Grid, TreeGrid, Tree, Combo, Scheduler, DataView, Chart, Form, DataStore components
When you need to update the values which were returned from a database table or set some specific formatting before sending data to the client side, you should use the beforeRender event handler.
$res= new PDO("mysql:dbname=$mysql_db;host=$mysql_server",$mysql_user,$mysql_pass);
require("../../codebase/grid_connector.php");
function color_rows($row){
if ($row->get_index()%2)
$row->set_row_color("red");
}
$grid = new GridConnector($res);
$grid->event->attach("beforeRender","color_rows");
$grid->render_table("grid50000","item_id","item_nm,item_cd");
APPLICABLE TO: Grid, TreeGrid, Tree, Combo, Scheduler, DataView, Chart, Form, DateStore components
function formatting($row){
//render a field as details link
$data = $row->get_value("some_field");
$row->set_value("some_field","<a href='details.php?id={$data}'>Details</a>");
//formatting a date field
$data = $row->get_value("other_field");
$row->set_value("other_field",date("m-d-Y",strtotime($data)));
}
$grid = new GridConnector($res);
$grid->event->attach("beforeRender","formatting");
APPLICABLE TO: Grid, TreeGrid, Tree, Combo, Scheduler, DataView, Chart, Form, DataStore components
More complex formatting rules can be defined by using extra fields during the configuration.
function formatting($row){
//set row color
$row->set_row_color($row->get_value("color"));
//save in userdata
$row->set_userdata("some_data",$row->get_value("count"));
}
$grid = new GridConnector($res);
$grid->event->attach("beforeRender","formatting");
$grid->render_table("some_table","id","name,price","color,count");
APPLICABLE TO: Tree, TreeGrid
TreeGrid provides TreeGridDataItem and Tree provides TreeDataItem as the input parameter of the beforeRender event handler. Both of them support base operations and a few specific ones.
function custom_format($item){
if ($item->get_value("complete")>75)
$item->set_check_state(1);
if ($item->get_value("duration")>10)
$item->set_image("true.gif");
else
$item->set_image("false.gif");
}
$tree->event->attach("beforeRender","custom_format");
While deleting items that have children you can face the problem that the parent item is deleted but its children are not. In this case you should use the beforeDelete event:
function beforeDeleteFunc( $data ) {
// custom logic
};
$conn->event->attach("beforeDelete","beforeDeleteFunc");
Back to top