JQGrid setRowData After inline edit

久未见 提交于 2020-01-24 01:45:20

问题


I'm having a problem updating a row after an inline edit. My ColModel is:

colModel: [
    { name: 'Email', index: 'Email', editable: true },
    { name: 'ReferenceEmail', index: 'ReferenceEmail', editable: true },
      // hidden: true, editable: true, editrules: { edithidden: true}
    { name: 'Title', index: 'Title', editable: true, edittype: "select",
      editoptions: { value: "Mr:Mr;Mrs:Mrs;Ms:Ms;Doctor:Doctor;Sir:Sir"} },
    { name: 'Forename', index: 'Forename', editable: true },
    { name: 'Surname', index: 'Surname', editable: true },
    { name: 'Study_Manager', index: 'Study_Manager', editable: true,
      edittype: "select", editoptions: { value: "True:True;False:False"} }
]

I plan to set the referenceemail col value = the new edited email value, so i have:

ondblClickRow: function (id, ri, ci) {
            lastSelUser = id;
            $("#UserGrid").editRow(id, true, false, reload);
        }

which in turn calls reload onsuccess of the edit,

function reload(result) {
    var cell = $("#UserGrid").getCell(lastSelUser, 'Email');
    var newEmail = $(cell).val();
    $("#UserGrid").saveRow(lastSelUser, false);

    $("#UserGrid").setRowData(lastSelUser, { ReferenceEmail: newEmail });


    var ref = $("#UserGrid").getCell(lastSelUser, 'ReferenceEmail');
    alert($(cell).val());
    alert($(ref).val());

}

Now my reference email doesnt get updated - the alert of the cell value returns correctly, but the alert of the ref(referenceemail) value is undefined and i've checked that the id is infact correct.

I've tried putting the saverow after the setRowData, but that makes no difference to the outcome.

Once again, I greatly appreciate any and all insight into the problem.

Regards, Byron Cobb


回答1:


I am not sure that I understood correctly your question.

It seems to me, that use should use aftersavefunc parameter of editRow instead of succesfunc (see http://www.trirand.com/jqgridwiki/doku.php?id=wiki:inline_editing#editrow). The event aftersavefunc will be called after the data will be saved in the jqGrid. The event succesfunc will be called only after $.ajax (no local data editing support) and immediately after the request completed before the data are saved in the grid.

The aftersavefunc event receive as parameters rowid - id of modified row, and res - response from the server. So if the ReferenceEmail field can be set by the server based on Email value you can use the results. To set ReferenceEmail field you can just use

$("#UserGrid").jqGrid('setCell',rowid,'ReferenceEmail', data);

where data is the new value of ReferenceEmail.




回答2:


A partial solution has been found for anyone wondering. The jqGrid editRow accepts the following paramaters:

jQuery("#grid_id").editRow(rowid, keys, oneditfunc, succesfunc, url, extraparam, aftersavefunc,errorfunc, afterrestorefunc

.setRowData doesnt seem to work in the succesfunc, but it does work in aftersavefunc, so my new call is $("#UserGrid").editRow(id, true, false, false, false, false, reload); instead of $("#UserGrid").editRow(id, true, false, reload);




回答3:


From the JQGrid documentation:

$("#updateButton").click( function(){
    var success=jQuery("#list5").jqGrid('setRowData',11,{amount:"333.00",tax:"33.00",total:"366.00",note:"<img src='images/user1.gif'/>"});

if(success) {
alert("Succes. Write custom code to update row in server"); 
}
   else {
       alert("Can not update");
}


来源:https://stackoverflow.com/questions/3227406/jqgrid-setrowdata-after-inline-edit

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!