Code below sets default values for new row if row is added using form. If row is added using jqGrid inline add button from toolbar, those methods are not called and default values are not set.
How to force inline add to perform same logic as code below ?
var lastSelectedRow;
$grid.navGrid("#grid_toppager", {
del: true,
add: true,
view: true,
edit: true
},
{},
{
addedrow: 'beforeSelected',
url: '/Grid/Add?_entity=Desktop',
beforeInitData: function () {
// todo: how to call this method from inline add
var rowid = $grid.jqGrid('getGridParam', 'selrow');
if (rowid === null) {
alert( 'Select row before adding');
return false;
}
},
afterShowForm: function(formID) {
// todo: how to set default values as this method sets from inline add
var selRowData,
rowid = $grid.jqGrid('getGridParam', 'selrow');
$('#' + 'Recordtype' + '.FormElement').val('Veerg');
$('#' + 'Nait2' + '.FormElement')[0].checked = true;
selRowData = $grid.jqGrid('getRowData', rowid);
$('#' + 'Baas' + '.FormElement').val(selRowData.Baas);
$('#' + 'Liigid' + '.FormElement').val(selRowData.Liigid);
}
);
$grid.jqGrid('inlineNav', '#grid_toppager', {
addParams: {
position: "beforeSelected",
rowID: '_empty',
useDefValues: true,
addRowParams: {
keys: true,
onEdit : onInlineEdit
}
},
editParams: {
editRowParams: {
onEdit : onInlineEdit
}
},
add: true,
edit: false,
save: true,
cancel: true
});
function onInlineEdit(rowId) {
if (rowId && rowId !== lastSelectedRow) {
cancelEditing($grid);
lastSelectedRow = rowId;
}
}
Update
I tried code
$grid.jqGrid('inlineNav', '#grid_toppager', {
addParams: {
position: "beforeSelected",
rowID: '_empty',
useDefValues: true,
addRowParams: {
keys: true,
extraparam: { _dokdata: FormData },
onSuccess : function (jqXHR) {
alert('addp oncuss');
jqXHRFromOnSuccess=jqXHR;
return true;
},
afterSave: function (rowID) {
alert('afeesave addp ');
cancelEditing($grid);
afterDetailSaveFunc(rowID,jqXHRFromOnSuccess);
jqXHRFromOnSuccess=null;
},
onError: errorfunc,
afterRestore : setFocusToGrid,
oneditfunc : function (rowId) {
var selRowData, selRowId ;
if (rowId && rowId !== lastSelectedRow) {
cancelEditing($grid);
selRowId = $grid.jqGrid('getGridParam', 'selrow');
if (selRowId ) {
selRowData = $grid.jqGrid('getRowData', selRowId );
$('#' + rowId + '_Reanr' ).val(selRowData.Reanr);
}
lastSelectedRow = rowId;
}
}
}
}
);
Only oneditfunc func is called. How to force onSuccess, afterSave, onError etc methods to be called also ?
Update 2
I added patch to jqGrid from github recommended in answer and tried
$.extend( jQuery.jgrid.inlineEdit, {
addParams: {
position: "beforeSelected",
rowID: '<%= EntityBase.NewRowIdPrefix %>',
useDefValues: true,
addRowParams: {
keys: true,
extraparam: { _dokdata: FormData },
onSuccess : function (jqXHR) {
jqXHRFromOnSuccess=jqXHR;
return true;
},
afterSave: function (rowID) {
cancelEditing($grid);
<% if (Model is RowBase ) { %>
afterDetailSaveFunc(rowID,jqXHRFromOnSuccess);
<% } else { %>
afterGridSaveFunc(rowID,jqXHRFromOnSuccess);
<% } %>
jqXHRFromOnSuccess=null;
},
onError: errorfunc,
afterRestore : setFocusToGrid,
oneditfunc : function (rowId) {
if (rowId && rowId !== lastSelectedRow) {
cancelEditing($grid);
lastSelectedRow = rowId;
}
}
}
}
} );
I this case enter does not terminate inline add. All parameters from this code are ignored.
You should use
defaultValue
property of the editoptions to set default values for the new added row. In the current documentation you can find that the option is valid only in Form Editing module:but if you examine the code of new addRow method you will see that
useDefValues
option istrue
defaultValue
property of the editoptions.UPDATED: OK! Now I see your problem. You used just wrong properties in
editRowParams
andaddRowParams
parts of the settings. Correct will be:Moreover you can use new $.jgrid.inlineEdit feature to set
keys
,oneditfunc
or other parameters of inline editing. The implementation of the feature is not full correct, but you can examine the current version from github (see here) and do the same modification in your version ofjquery.jqGrid.src.js
. In any way I would recommend to use the $.jgrid.inlineEdit feature after publishing the next version of jqGrid. The advantage is that you can easy set options ofeditRow
independent from where the function will be called (frominlineNav
,'actions'
formatter or any other way).New
jqGridInlineEditRow
event feature (see here for more information) will allow you to implement actions like what you do now inside ofonInlineEdit
event without the usage ofoneditfunc
which can be set only one time.