内联编辑后发生的事件

时间:2016-05-27 18:04:13

标签: asp.net-mvc-4 jqgrid jqgrid-asp.net

我有jqgrid,它在选择行时将行的数据发送到另一个视图(MVC4)。但是当我编辑行的信息(我正在使用内联编辑)时,此视图不会更改。我无法找到内联编辑后发生的事件。这是js,我应该在行编辑后更改我的视图

  $(function () {
$("#GridTable").jqGrid({
    url: "/Goods/GoodsList",
    editurl: "/Goods/Edit",
    datatype: 'json',
    mtype: 'Get',
    colNames: ['GoodId', 'Имя', 'Цена'],
    colModel: [
        { key: true, hidden: true, name: 'GoodId', index: 'GoodId', editable: true },
        {
            key: false, name: 'GoodName', index: 'GoodName', editable: true, sortable: true,
            editrules: {
                required: true, custom: true, custom_func: notATag
            }
        },
        {
            key: false, name: 'Price', index: 'Price', editable: true, sortable: true, formatter: numFormat,
            unformat: numUnformat,
            //sorttype: 'float',
            editrules: { required: true, custom: true, custom_func: figureValid}
        }, ],
    pager: jQuery('#pager'),
    rowNum: 10,
    rowList: [10, 25, 50, 100],
    height: '100%',
    viewrecords: true,
    caption: 'Список товаров',
    sortable: true,
    emptyrecords: 'No records to display',
    cellsubmit : 'remote',
    jsonReader: {
        root: "rows",
        page: "page",
        total: "total",
        records: "records",
        repeatitems: false,
        Id: "0"
    },
    //to get good's full view when row is selected
    onSelectRow:

        function () {
            var myGrid = $('#GridTable'),
            selRowId = myGrid.jqGrid('getGridParam', 'selrow'),
            celValue = myGrid.jqGrid('getCell', selRowId, 'GoodId');
            $.ajax({
                url: "/Goods/DetailInfo",
                type: "GET",
                data: { id: celValue }
            })
            .done(function (partialViewResult) {
                $("#goodDetInfo").html(partialViewResult);
            });
        },
    //to change good's full view after row deleting
    loadComplete: function(data){
        var myGrid = $('#GridTable'),
            selRowId = myGrid.jqGrid('getGridParam', 'selrow'),
            celValue = myGrid.jqGrid('getCell', selRowId, 'GoodId');
        $.ajax({
            url: "/Goods/DetailInfo",
            type: "GET",
            data: { id: celValue }
        })
        .done(function (partialViewResult) {
            $("#goodDetInfo").html(partialViewResult);
        });
    },
    autowidth: true,
    multiselect: false
}).navGrid('#pager', { edit: false, add: true, del: true, search: false, refresh: true },
    {
        // edit options
        zIndex: 100,
        url: '/Goods/Edit',
        closeOnEscape: true,
        closeAfterEdit: true,
        recreateForm: true,
        afterComplete: function (response) {
            if (response.responseText) {
                alert(response.responseText);
            }
            var myGrid = $('#GridTable'),
            selRowId = myGrid.jqGrid('getGridParam', 'selrow'),
            celValue = myGrid.jqGrid('getCell', selRowId, 'GoodId');
            $.ajax({
                url: "/Goods/DetailInfo",
                type: "GET",
                data: { id: celValue }
            })
            .done(function (partialViewResult) {
                $("#goodDetInfo").html(partialViewResult);
            });
        }
    },
    {
        // add options
        zIndex: 100,
        url: "/Goods/Create",
        closeOnEscape: true,
        closeAfterAdd: true,

        afterComplete: function (response) {
            if (response.responseText) {
                alert(response.responseText);
            }
        }
    },
    {
        // delete options
        zIndex: 100,
        url: "/Goods/Delete",
        closeOnEscape: true,
        closeAfterDelete: true,
        recreateForm: true,
        msg: "Are you sure you want to delete this task?",
        afterComplete: function (response) {
            if (response.responseText) {
                alert(response.responseText);
            }
        }
    });

$('#GridTable').inlineNav('#pager', {
    edit: true,
    add: false,
    del: false,
    cancel: true,
    editParams: {
        keys: true,
        afterSubmit: function (response) {
            if (response.responseText) {
                alert(response.responseText);
            }
            var myGrid = $('#GridTable'),
            selRowId = myGrid.jqGrid('getGridParam', 'selrow'),
            celValue = myGrid.jqGrid('getCell', selRowId, 'GoodId');
            $.ajax({
                url: "/Goods/DetailInfo",
                type: "GET",
                data: { id: celValue }
            })
            .done(function (partialViewResult) {
                $("#goodDetInfo").html(partialViewResult);
            });
        }
    },
});

});

1 个答案:

答案 0 :(得分:0)

可以找到editParams的{​​{1}}参数的属性和回调函数here。您需要的可能是inlineNavaftersavefunc而不是successfunc,它们仅存在于表单编辑方法中(请参阅here)。 afterSubmitaftersavefunc回调的参数描述为here(作为successfunc的参数),但参数取决于您使用的jqGrid的版本以及来自fork的版本jqGrid(free jqGrid,商业Guriddo jqGrid JS或版本中的旧jqGrid< = 4.7)。我开发了免费的jqGrid fork,我建议你使用当前(4.13.3)版本的免费jqGrid。