Hi
I have a table with tree fields: ‘key’, ‘name’ and ‘value’
In the grid ‘key’ is hidden and is used just to filter the grid from a url variable, example https://mydomain.com/grid.pgp?key=1234 will only shows registers with key=1234, that works fine.
If the user wants to add a new register the dialog only asks form fields ‘name’ and ‘value’, that’s right, but I need also insert the ‘key’ value with a preset value (in this example ‘1234’)
Is there any way to get this behavior?
I’ve found the way, but something does not work ok. This is the code of the first field:
$col = array();
$col[“title”] = “UUID”;
$col[“name”] = “UUID”;
$col[“width”] = “20”;
$col[“editoptions”] = array(“defaultValue”=> $_GET[‘key’]);
$col[“editable”] = true;
$cols[] = $col;
When I add a new record, the UUID value is right:
But when I add the register, the first field is always recorded as NULL:
Any idea?
Sorry, the screenshots:
Add dialog:
and data stored in table:
Hello,
You can try following:
Show a grid that contains all fields. (key, name, value) and you can make key field hidden = true and editable = false; It won’t show key in listing/add/edit screens.
To filter the grid on page load via URL, you can use this: ($g is grid object)
$k = isset($_GET["key"]) ? $_GET["key"] : "0"; $g->select_command = "SELECT name, value FROM table1 WHERE key = $k";
Now to insert the key while insertion, You can use on_insert event handler: for e.g.
$e["on_insert"] = array("add_data", null, true); $g->set_events($e); function add_data($data) { $data["params"]["key"] = $_GET["key"]; }
For more details on grid events, refer this link.
PS: Events are supported in full version if not already using.