简体   繁体   中英

How to keep inline add if error is returned on pressing save action button in jqgrid

jgGrid contains inline add button in toolbar and save action button in action column. Remote json data is used. If save action button is pressed to terminate inline add and server returns error, added row is removed from grid and entered row data is lost. I added restoreAfterError:false to formatoptions and to inline add button as shown in code below but those settings are ignored if save action button is pressed.

How to keep row in inline add mode so that edit can continue after error if save action button is pressed?

colModel: [ {
  name:"_actions",
  formatter:"actions",
  formatoptions:{
    editbutton:true,
    keys:true,
    // this is ignored if action column save button is pressed:
    restoreAfterError:false,
    delbutton:true
    }
} , ...
], 
editurl: '/Grid/Edit',
datatype: "json",

inline add button is added using:

$grid.jqGrid('inlineNav', '#grid_toppager', {
    addParams: {
        position: "beforeSelected", 
        rowID: '_empty',
        useDefValues: true,
        addRowParams: {
            keys: true,
            // this is ignored if action column save button is pressed:
            restoreAfterError: false,
        }
    },

    editParams: {
            keys: true,
            // this is ignored if action column save button is pressed:
            restoreAfterError: false,
    },

   add: true,
   edit: false,
   save: true,
   cancel: true
});

I tested the settings restoreAfterError: false inside of addParams.addRowParams or editParams and it works good. In case of error the editing (or new added row) stay in the editing mode after the error message are displayed by my custom errorfunc . I suppose you had problems only in case of usage of formatter: 'actions' .

If you use the formatter: 'actions' you have no way to define restoreAfterError directly (at least in the current jqGrid version 3.4.1). So I recommend you to change the default value of restoreAfterError to false :

$.extend($.jgrid.inlineEdit, {
    restoreAfterError: false
});

Additionally I recommend you remove trailing comma (like here restoreAfterError: false,} ) from the addRowParams or editParams . Trailing commas are ignored by many (but not all) of web browsers, but there are still an error.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM