使用动作进行jqgrid内联编辑 - 无法显示错误消息

时间:2016-09-21 08:14:07

标签: javascript jquery angularjs jqgrid

我正在使用带编辑操作按钮的jQgrid内联编辑,但 aftersavefunc 无效。什么是正确的方法呢?

我希望从服务器收到时恢复行并显示错误消息: {“成功”:false,“id”:null,“message”:“你不能那样做”}

以下是我的代码:

 angular.element(document).ready(function () {

    $("#jqGrid").jqGrid({
        datatype: "local",
        data: $scope.listResellerUser,
        mtype: "POST",
        colModel: [
            { label:'Full Name', name: 'fullname' },
            { label: 'User Name', name: 'username' },
            { label: 'User Id', name: 'userId', hidden: true, key:true },
            { label: 'Email', name: 'email' },
            { label: 'User Level', name:'roleId', index:'roleId', edittype:'select', editable:true, align:'center', formatter:'select', 
                editoptions:{value:setRoleDropdown()
            }},
            {name:'Actions',index:'Actions',width:55,align:'center',sortable:false,search: false,formatter:'actions',
                 formatoptions:{
                     keys: true, // we want use [Enter] key to save the row and [Esc] to cancel editing.
                     delbutton:false,
                 }}

        ],
        editurl: "/myreseller/changeuserrole",
        styleUI : 'Bootstrap',
        page: 1,
        autowidth: true,
        height: 250,
        rowNum: 20,
        scrollPopUp:true,
        scrollLeftOffset: "83%",
        viewrecords: true,
        scroll: 1, // set the scroll property to 1 to enable paging with scrollbar - virtual loading of records
        emptyrecords: 'Scroll to bottom to retrieve new page', // the message will be displayed at the bottom 
        pager: "#jqGridPager",
        editParams: {
            "aftersavefunc": function (rowid, response, options) {
                alert("row with rowid=" + rowid + " is successfuly modified.");
            }
        }
    });

1 个答案:

答案 0 :(得分:0)

首先,重要的是要包含有关您使用的jqGrid版本(或您可以使用的)以及jqGrid(free jqGrid,商业Guriddo jqGrid JS或旧jqGrid的分支的信息。在您的问题文本中的版本< = 4.7)。

我开发了免费的jqGrid fork,它也支持Bootstrap(参见here)。因此,我无法帮助你解决Guriddo jqGrid JS的具体问题。在我看来,你使用不存在的选项editParams。免费的jqGrid允许通过inlineEditing选项指定常见的内联编辑选项(请参阅the wiki article)。如果你留在商业Guriddo jqGrid JS,那么你可能必须在formatter:'actions'内指定formatoptions的回调函数(参见onSuccess的{​​{3}},onError },afterSave和其他回调)。

此外,在您的情况下,回调aftersavefunc似乎是错误的选择。在服务器响应的处理之后,它将被称为。来自editurl的成功HTTP状态代码的每个响应都将被解释为成功,并且更改(错误更改)将保存在网格中。可以通过使用errorfunc回调并返回一些错误HTTP状态代码(> = 400)或使用successfunc回调来解决问题,这允许处理服务器响应的内容并返回{ {1}}或[false, "error text"]取决于服务器响应的内容。在我看来,这就是你所需要的。