Hello I hope you can help me.
I have successfully created a function for "on_after_insert" which need access to $data attributes of the current selected object. Now I created a custom button for add/edit form and I want to call this function by clicking this button.
How can I handle this?
The function on_after_insert is automatically called when you perform insert operation.
It will be called on add dialog submit button.
Usual add process flow is:
on_insert is called
grid insert operation is called (if 3rd param is true in on_insert setting)
on_after_insert is called.
If you can explain complete business case, i can suggest some solution.
Thanks for your answer and help. The business case is, that we have to generate an inventory number for added items in the db. The function for this is acutally
function after_insert($data)
{ … }
That works great but sometimes not all data is provided at the time the item is added to the db. So I want to call the function through an added button on the edit view. The need is to call the $data variable to access attributes of selected row.
The on_after_insert $data variable will have all data submitted from add form.
In event handler of on_insert, only data missing will be ID because it does not exist before insert.
When we get $data in on_after_insert it is filled internally by grid api, to top level key. .e.g
function after_insert($data)
{
/*
These comments are just to show the input $data format
Array
(
[client_id] => 99 // FILLED BY GRID API
[params] => Array
(
[client_id] => // BLANK BECAUSE IT DOES NOT EXIST AT TIME OF INSERT
[name] => Test
[gender] => male
[company] => Comp Test
)
)
*/
}
Hope it help.
Thanks for your reply, that helped me with another task.
But what I really need is to call the code from
function after_insert($data) { } by an .click(function() {}
how can i access data through function (similiar $data for an after_insert) of the selected row when i use the
$grid["add_options"]["afterShowForm"] = 'function (form)
{ .click(function() }
Hope the explanation helps
Please check if this help … To call insert operation via JS code, you can check:
http://www.phpgrid.org/faqs/#71
Thanks that was a huge help!
Now i can read and output data with:
var selr = jQuery('#list1').jqGrid('getGridParam','selrow');
varrd=jQuery('#list1').jqGrid('getCell',selr,'Lieferant');
alert(selr);
alert(rd);
but if i want to post something like in http://www.phpgrid.org/faqs/#71
I get an error:
200 : OK. Status: parsererror
I don't want to add a new row but update a cell entry with new data
You need put to at the end of my custom insert.
$res = array("id" => $id, "success" => true);
echo json_encode($res);
where $id is newly created id