why when using inline insert, the grid wont refresh after save.
im using custom sql query
here's the example using dummy data
$opt["on_insert"] = array("add_purchase_request_detail", null, false);
function add_purchase_request_detail()
{
global $grid2;
$str = "INSERT INTO
purchase_request_detail
(
purchase_request_id
)
VALUES
(
'1'
)";
$grid2->execute_query($str);
}
error caught on console,
when set opt to true, no error, and grid will refreshed
$opt["on_insert"] = array("add_purchase_request_detail", null, true);
here's the error caught:
jquery.min.js:4 Uncaught SyntaxError: Unexpected end of inputn.parseJSON @
jquery.min.js:4jQuery.jqGrid.addParams.addRowParams.aftersavefunc @ purchase.php:381a.ajax.a.extend.complete @ jquery.jqGrid.min.js:399j @ jquery.min.js:2k.fireWith @ jquery.min.js:2x @ jquery.min.js:4b @ jquery.min.js:4send @ jquery.min.js:4n.extend.ajax @ jquery.min.js:4a.jgrid.extend.saveRow @ jquery.jqGrid.min.js:398b.fn.jqGrid @ jquery.jqGrid.min.js:34e.save.a.jqGrid.onClickButton @ jquery.jqGrid.min.js:409(anonymous function) @ jquery.jqGrid.min.js:361n.event.dispatch @ jquery.min.js:3r.handle @ jquery.min.js:3n.event.trigger @ jquery.min.js:3(anonymous function) @ jquery.min.js:3n.extend.each @ jquery.min.js:2n.fn.n.each @ jquery.min.js:2n.fn.extend.trigger @ jquery.min.js:3n.fn.(anonymous function) @ jquery.min.js:4onclick @ purchase.php:1
Hi,
The inline add should return a JSON string with convention: e.g. id:insert_id, success:true
{"id":21,"success":true}
So in your callback (with continue_default:false), you must return json string as mentioned below:
$opt["on_insert"] = array("add_purchase_request_detail", null, false);
$grid->set_events($opt);
function add_purchase_request_detail()
{
…
$id = $grid2->execute_query($str,"insert_id");
$res = array("id" => $id, "success" => true);
echo json_encode($res);
}
thankyou, that solved my problem.
then, is it possible if i dont want to use execute query
for this line:
$id = $grid2->execute_query($str,"insert_id");
instead i want to use traditional method:
mysqli_query($conn, $sql)
thankyou
oh, i got it
use mysqli_insert_id($conn), return the same thing.
what if i dont pass id to JSON array?
like this :
$res = array("success" => true);
echo json_encode($res);
I also got no error using this method.
I just want to know what does the ID passed to JSON array for?
thankyou for your answer