php - jqGrid after Delete error -
here example delete options i'm using using in jqgrid. works fine , serverside scripts working perfectly. records deleted, there goes wrong after response server received.
// del options { mtype: "post", modal: true, url: "/internal/backupmanagement/backupmanager/deletemysqldb", reloadaftersubmit: false, onclicksubmit: function () { var post = $("#grid_" + o.id).jqgrid("getgridparam", "postdata"); var server = post.serverid; $.opendialog("load", "deleting old database entry. please wait..."); var selrow = $("#grid_" + o.id).jqgrid("getgridparam", "selrow"); var row = $("#grid_" + o.id).jqgrid("getrowdata", selrow); console.log("about return", row, server); return { id: row.recid, database: row.database, server: server }; }, aftersubmit: function (response, postdata) { response = eval("(" + response.responsetext + ")"); console.log(response); return [true, "success"]; }, aftercomplete: function (response, postdata, formid) { response = eval("(" + response.responsetext + ")"); var selrow = $("#grid_" + o.id).jqgrid("getgridparam", "selrow"); $("#grid_" + o.id).jqgrid("delrowdata", selrow); if (response.error == 0) { $.opendialog("info", "successfully deleted " + postdata.database + "."); } else { $.opendialog("info", "and error occured - " + response.msg + "."); } } }
i following error before aftercomplete event fired in grid :
uncaught typeerror: object [object array] has no method 'split'
so seems being returned object when expecting string. i'm not sure if response server formatted correctly , wasn't able find expected response in documentation either.
* update * server-side code requested. i've included controller function interacts jqgrid, rest working , happening further on in application.
function deletemysqldb() { if (is_ajax) { if (($this->application->deletemysqldbdata( $_post["id"], $_post["database"], $_post["server"] )) === false) { echo json_encode( array( "error" => 1, "msg" => "failed deleting record database: " .$this->application->error ) ); return false; } echo json_encode( array( "error" => 0, "msg" => "success" ) ); return true; } else { header("location: /"); } }
i hope helps see i'm returning grid.
* update * have done changed source in jqgrid plugin include tostring() on value before preforming split.
on line 331 of jquery.jqgrid.min.4.3.1 :
var a=[];a=h.split(",");
changed :
var a=[];a=h.tostring().split(",");
it seemed harmless change in grand scheme of things , avoids arrays attempted split. lot guys. pointed me in right place start looking, oleg!
let's suppose origin of described error code of aftercomplete
callback. think using in wrong way. don't understand parts of code, part (testing of response.error
) should moved in aftersubmit
.
the main problem clear if examine the lines of code aftercomplete
callback called. executed inside of settimeout
0.5 sec delay. @ time new data in grid can loaded (or loading). wrong use methods delrowdata
, value of selrow
changed now.
i strictly recommend additionally don't use eval
function. instead of line
response = eval("(" + response.responsetext + ")");
it correct use
response = $.parsejson(response.responsetext);
the code of onclicksubmit
callback improved if use fact this
inside of callback (like other callbacks o jqgrid) initialized dom element of grid. selrow
option of grid can use
var selrow = $(this).jqgrid("getgridparam", "selrow");
instead of
var selrow = $("#grid_" + o.id).jqgrid("getgridparam", "selrow");
another fact onclicksubmit
called jqgrid 2 parameters: options
, postdata
. parameter postdata
rowid if use don't use multiselect: true
. in case of usage of multiselect: true
value of postdata
parameter of callback can comma separated list of rowids of rows deleted. usage of postdata
better usage of selrow
.
Comments
Post a Comment