When I add a new row to the grid, in one of my fields which is number, im trying to auto-increment it using the last number I had in the last row, How can i get that last row value and how can i set it to be a defaultValue.
Thanx for the help.
For that, you need to use 'on_insert' event for a custom callback function.
In that function callback, you can have a select sql, that will fetch last id from database, and set an incremented id in the field before actual insert takes place.
// params are array(<function-name>,<class-object> or <null-if-global-func>,<continue-default-operation>)
// if you pass last argument as true, functions will act as a data filter, and insert/update will be performed by grid
$e["on_insert"] = array("add_client", null, true);
// fetch last id using mysql_query, be it in var $new_id
// now just set it for database insert
$data["params"]["myfield"] = $new_id;
How useful was this discussion?
Click on a star to rate it!
Average rating / 5. Vote count:
We are sorry that this post was not useful for you!
Let us improve this post!
Thanks for your feedback!