Is it possible to do something like this where params are in one detail table and sql update acts on another table? Is there a better way to do this it does not seem to work?
$e["on_update"] = array("update_paytbl", null, true);
$g->set_events($e);
function update_paytbl($data)
{
$room_count = 0;
$hotel_cost = 0;
if($data["params"]["hotel"] == 'Holiday Inn'){
$room_count = $room_count + 1;
}
if($data["params"]["roommate1"] == 'Yes'){
$room_count = $room_count + 1;
}
if($data["params"]["roommate2"] == 'Yes'){
$room_count = $room_count + 1;
}
if($data["params"]["roommate3"] == 'Yes'){
$room_count = $room_count + 1;
}
$hotel_cost = ($data["params"]["hotel_nbr_nights"] * 100.00)/$room_count;
$hotel_cost = number_format((float)$hotel_cost, 2, '.', '');
$str = "UPDATE hotel_pay SET hotel='".$hotel_cost."'
WHERE member_id = {$data["member_id"]}";
mysql_query($str);
}
I guess, thats the simplest way.
You better debug the $data, $str and check the mysql_error() message.
e.g.
function update_paytbl($data)
{
…
print_r($data);
echo $str;
echo mysql_error();
}
You can see the output in firebug ajax call response.
https://phpgrid.desk.com/customer/portal/articles/926266
Thanks Abu! After these (1 (2) (3) changes (please see below), the query works and the other detail table is updated.
Now, the only way I can "see" the changes in the other detail table is to manually click that grid's reload button. Is there a way to add a statement to the handler to reload the other detail table?
$e["on_update"] = array("update_paytbl", null, true);
$g->set_events($e);
function update_paytbl($data)
{
(1) $id = intval($_GET["rowid"]);
(2) $data["params"]["member_id"] = $id;
$room_count = 0;
$hotel_cost = 0;
if($data["params"]["hotel"] == 'Holiday Inn'){
$room_count = $room_count + 1;
}
if($data["params"]["roommate1"] == 'Yes'){
$room_count = $room_count + 1;
}
if($data["params"]["roommate2"] == 'Yes'){
$room_count = $room_count + 1;
}
if($data["params"]["roommate3"] == 'Yes'){
$room_count = $room_count + 1;
}
$hotel_cost = ($data["params"]["hotel_nbr_nights"] * 100.00)/$room_count;
$hotel_cost = number_format((float)$hotel_cost, 2, '.', '');
$str = "UPDATE hotel_pay SET hotel='".$hotel_cost."'
(3) WHERE member_id = {$data["params"]["member_id"]}";
mysql_query($str);
}
You can use onaftersave function callback.
// reload list1, after detail update
$opt["onAfterSave"] = "function(){ jQuery('#list1').trigger('reloadGrid',[{jqgrid_page:1}]); }";
I am also sending you updated lib and demo.
Thanks for the example and updated library.
Using the example, I added the callback before the set_options section within the section for the first detail grid (list2). However, I need to reload the second detail grid (list3), so I changed the function to…
$opt["onAfterSave"] = "function(){ jQuery('#list3').trigger('reloadGrid',[{jqgrid_page:1}]); }";
Unfortunately, this doesn't reload that grid (list3).
Also, the new library resulted in replacement of the "icons" in the inline edit Action column with text links. Should that be happening?
I don't know what possibly could be the reason, as i sent your working example after testing.
You can share the code (using pastebin.com). I'll recheck it.
For icons, goto jqgrid_dist.php, and search for actionicon and set
$this->internal["actionicon"] = true;
Could you please send me the working demo of Grid Reload discussed above?
Thanks,
Talha
http://hastebin.com/ekuwatunoz.php (line 67)
// reload parent on update
$grid["onAfterSave"] = "function(){ jQuery('#list1').trigger('reloadGrid',[{jqgrid_page:1}]); }";
// reload parent on add
$grid["add_options"]["afterSubmit"] = "function(){jQuery('#list1').trigger('reloadGrid',[{jqgrid_page:1}]); return [true, ''];}";
You can replace list1 with the grid id which you want to reload.