access $data in $grid["edit_options"]["afterShowForm"] = 'function (form)

Questionsaccess $data in $grid["edit_options"]["afterShowForm"] = 'function (form)
Fabian asked 7 years ago

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?

8 Answers
Abu Ghufran answered 7 years ago

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.

Fabian answered 7 years ago

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.

Abu Ghufran answered 7 years ago

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.

Fabian answered 7 years ago

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

Abu Ghufran answered 7 years ago

Please check if this help … To call insert operation via JS code, you can check:
http://www.phpgrid.org/faqs/#71

Fabian answered 7 years ago

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

Abu Ghufran answered 7 years ago

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

Fabian answered 7 years ago

Thanks for your reply I was now able to update my cell value with:
$('#list1').jqGrid("setCell", selr, "Lieferant", "New value");

Your Answer

6 + 12 =

Login with your Social Id:

OR, enter

Attach code here and paste link in question.
Attach screenshot here and paste link in question.



How useful was this discussion?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate it.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?