Hi
I am converting a field value for display in a grid (converting from lbs to kg with a small function) in the grid set events/filter display section e.g.:
$g->set_events($e);
function filter_display($data);
foreach($data[“params”] as &$d)
{
// for each row, convert the retrieved amounts from LBS to KG
$d[“FlightFuel”]=convertlbstokg($d[“FlightFuel”]);
$d[“BlockFuel”]= convertlbstokg($d[“BlockFuel”]);
$d[“Cargo”]= convertlbstokg($d[“Cargo”]);
}
etc etc.
The grid is set to be editable, so whenever I edit a row value it saves the fuel and cargo values back as kg (i.e. the converted value) when it should be in lbs. I can write a function to convert the values back to lbs but where in the code flow can I do this? I can’t see where it updates the tables with edited grid values.
Hello,
This code can be added in on_update event handler. And call similar conversion before it is inserted in database.
https://www.gridphp.com/docs/grid-events/
e.g.
If the 3rd argument is true, the function will behave as a data filter and the final update will be done by grid code.
$e["on_update"] = array("update_client", null, true);
...
function update_client(&$data)
{
// set current date time internally
$data["params"]["BlockFuel"] = convertkgtolbs($data["params"]["BlockFuel"]);
}