簡體   English   中英

使用動作進行jqgrid內聯編輯-無法顯示錯誤消息

[英]jqgrid inline editing using actions - not able to show error messsage

我正在使用帶有編輯操作按鈕的jQgrid內聯編輯,但是aftersavefunc無法正常工作。 正確的方法是什么?

當我從服務器收到消息時,我想還原該行並顯示錯誤消息: {“成功”:false,“ id”:null,“消息”:“您不能這樣做”}

以下是我的代碼:

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

首先,重要的是,在其中包含有關您使用(或可以使用)的jqGrid版本信息以及jqGrid的分支( 免費jqGrid ,商業Guriddo jqGrid JS或版本<= 4.7的舊jqGrid)。您的問題的文字。

我開發了免費的jqGrid fork,它也支持Bootstrap(請參閱此處 )。 因此,對於Guriddo jqGrid JS的特定問題,我無能為力。 在我看來,但是您使用了不存在的選項editParams 免費的jqGrid允許通過inlineEditing選項指定常見的內聯編輯選項(請參閱wiki文章 )。 如果您不使用商業Guriddo jqGrid JS,則可能必須指定formatter:'actions'的回調函數formatter:'actions' formatoptions內部的formatter:'actions' (請參閱onSuccessonErrorafterSave和其他回調的文檔 )。

此外,在您的情況下,回調aftersavefunc似乎是錯誤的選擇。 處理服務器響應后將調用它。 來自editurl每個帶有成功HTTP狀態代碼的響應都將被解釋為成功,並且editurl的更改(錯誤更改)將保存在網格中。 可以通過使用errorfunc回調並返回一些錯誤的HTTP狀態代碼(> = 400)或通過使用successfunc回調來解決問題,該方法允許處理服務器響應的內容並返回[false, "error text"][true]取決於服務器響應的內容。 在我看來,這就是您所需要的。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM