jquery - jqGrid with inlineNav: is there a way to force the Add button to re-enable? -
i'm using jqgrid 4.3.2 inlinenav option. editing on grid done locally using loadonce: true , clientarray. when user finishes editing, click save button on form , entire grid posted server. works great, part, i've run oddity. if user adds new row , clicks save button before hitting enter confirm edit or deselecting newly added row, add button on inline navigator remains disabled after calling saverow before posting , reloading. i've tried resetselection , restorerow after saverow call, neither of these work. save code:
$("#submitbutton").click(function () { $("#thegrid").jqgrid('saverow', $("#selectedrowid").val(), false, 'clientarray'); if (!validategriddata()) return false; var rowdata = $("#thegrid").jqgrid('getrowdata'); var datatosend = json.stringify(rowdata); $.ajax({ url: '@url.action("updategriddata")', type: 'post', contenttype: 'application/json; charset=utf-8', data: datatosend, datatype: 'json', async: false, success: function (data, textstatus, jqxhr) { $("#thegrid").jqgrid('setgridparam', { datatype: 'json' }); $("#thegrid").trigger('reloadgrid'); }, error: function (jqxhr, textstatus, errorthrown) { alert('error saving data: ' + textstatus + " " + errorthrown); } }); return true; }); is there way can convince inline navigator new row saved , user can add more rows?
the buttons added in navigator inlinenav method has ids constructed grid id , corresponding suffix:
- add: gridid + "_iladd" (for example "list_iladd")
- edit: gridid + "_iledit" (for example "list_iledit")
- save: gridid + "_ilsave" (for example "list_ilsave")
- cancel: gridid + "_ilcancel" (for example "list_ilcancel")
to enable button should remove 'ui-state-disabled' css class:
var gridid = "list"; $("#" + gridid + "list_iladd").removeclass('ui-state-disabled'); to disable button 1 can use .addclass('ui-state-disabled') instead.
additionally don't recommend use inline editing methods saverow directly. in case not have problem try solve. @ code the answer. defines editingrowid , myeditparam as
var $grid = jquery("#list"), editingrowid, myeditparam = { keys: true, oneditfunc: function (id) { editingrowid = id; }, afterrestorefunc: function (id) { editingrowid = undefined; } }; and use inlinenav myeditparam parameter:
$grid.jqgrid('inlinenav', '#pager', { edit: true, add: true, editparams: myeditparam, addparams: {addrowparams: myeditparam } }); in case can sure editingrowid id of current editing row or undefined if no row editing. can use $(grididselector + "_iledit").click(); instead of editrow edit current selected row. in same can use setselection if needed , simulate click on other inline editing navigator buttons.
updated: if need can still combine calls of saverow inside of onselectrow, can first use variable editingrowid , seconds use myeditparam common editing ways use:
onselectrow: function (id) { var $this = $(this); if (editingrowid !== id) { if (editingrowid) { // save or restore editing row $this.jqgrid("saverow", editingrowid, myeditparam); // or $this.jqgrid("restorerow", editingrowid, myeditparam); } $this.jqgrid("editrow", editingrowid, myeditparam); } } if need other options of inline editing methods can include there in myeditparam. see editingrowid better use lastsel variable find in inline editing examples.
Comments
Post a Comment