I’m struggling with what I think is a simple problem but I can’t seem to solve it.
I want to include a column on my grid that is not a database column but that I can edit and does not break your insert.
I have a table (mytable) with 2 fields. F1 & F2
I want my grid to display columns F1, F2 and F3 where F3 is a non-database column, editable and which I will use in an insert event to modify one of the table fields.
If I define the grid select as “select *, “ ” as F3 from mytable” the grid displays fine but when I try to insert a record it fails with “Couldn’t execute query. Unknown column ‘F3’ in ‘field list’”
I know I can work around this by handling the insert myself in the insert event but before I do I thought I’d ask you first if there was a simpler way
For non-db editable column, you need to use custom on_insert event code as grid library does not understand that it does not exist in table.
When using on_insert, There are 2 options.
$e[“on_insert”] = array(“add_client”, null, true); …. OR
$e[“on_insert”] = array(“add_client”, null, false);
When you set 3rd param to true, both your code and grid code will be executed and in later case only your custom code will be executed with no grid based insert query.
So, what you can do is to make 3rd param true and process your custom column f3, then unset it and leave other insert to be performed by grid.
// perform insert call on f3 and to avoid insert error unset it.
More here: https://www.phpgrid.org/docs/grid-events/
Abu Ghufran - Dev Team
PHP Grid Framework
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!