【问题标题】:jqgrid inline editing using actions - not able to show error messsage使用操作的 jqgrid 内联编辑 - 无法显示错误消息
【发布时间】:2017-01-29 09:00:47
【问题描述】:

我正在使用带有编辑操作按钮的 jQgrid 内联编辑,但 aftersavefunc 不起作用。什么是正确的做法?

当我从服务器收到时,我想恢复该行并显示错误消息:{"success":false,"id":null,"message":"You can not do that"}

以下是我的代码:

 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.");
            }
        }
    });

【问题讨论】:

    标签: javascript jquery angularjs jqgrid


    【解决方案1】:

    首先,重要的是要包含有关您使用(或可以使用)的 jqGrid 版本和 jqGrid 的分支(free jqGrid、商业Guriddo jqGrid JS 或版本中的旧 jqGrid 的信息

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-10
      • 2020-09-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多