The buttons added in the navigator using inlineNav have identifiers that are built from the grid identifier and the corresponding suffix:
- Add: gridId + "_iladd" (for example, "list_iladd")
- Edit: gridId + "_iledit" (e.g. "list_iledit")
- Save: gridId + "_ilsave" (for example, "list_ilsave")
- Cancel: gridId + "_ilcancel" (for example, "list_ilcancel")
To enable the button, you must remove the 'ui-state-disabled'
CSS class:
var gridId = "list"; $("#" + gridId + "list_iladd").removeClass('ui-state-disabled');
To disable a button, you can use .addClass('ui-state-disabled')
.
In addition, I do not recommend you use any built-in editing methods, such as saveRow
. In case you probably will not have the problem you are trying to solve. Look at the answer code. It defines editingRowId
and myEditParam
as
var $grid = jQuery("#list"), editingRowId, myEditParam = { keys: true, oneditfunc: function (id) { editingRowId = id; }, afterrestorefunc: function (id) { editingRowId = undefined; } };
and then use inlineNav
with the myEditParam
parameter:
$grid.jqGrid('inlineNav', '#pager', { edit: true, add: true, editParams: myEditParam, addParams: {addRowParams: myEditParam } });
In this case, you can be sure that editingRowId
will get the identifier of the current edit line or undefined
if no line is being edited. This way you can use $(gridIdSelector + "_iledit").click();
instead of editRow to edit the currently selected row. In this case, you can use setSelection , if necessary, and simulate a click on any other built-in navigation edit buttons.
UPDATED . If you need to, you can still combine saveRow
calls inside onSelectRow
, but first you can use the editingRowId
variable and use the seconds myEditParam
, which will be common for all the editing methods that you use:
onSelectRow: function (id) { var $this = $(this); if (editingRowId !== id) { if (editingRowId) { // save or restore currently editing row $this.jqGrid("saveRow", editingRowId, myEditParam); // or $this.jqGrid("restoreRow", editingRowId, myEditParam); } $this.jqGrid("editRow", editingRowId, myEditParam); } }
If you need other variations of the built-in editing methods, you can include them in myEditParam
. You will see that editingRowId
much better used as the lastSel
variable, which you will find in most built-in editing examples.