【问题标题】:jqGrid: Why aren't the events that I defined for a grid edit firing?jqGrid:为什么我为网格编辑定义的事件没有触发?
【发布时间】:2009-09-04 21:38:09
【问题描述】:

我正在网格上进行内联编辑,但似乎无法触发与该编辑相关的任何事件。

这里我有 afterSubmit: 我希望它在用户编辑网格中的 Quantity 字段后触发,但它永远不会触发。

$('#tblLines').jqGrid({
        url: createUrl('/CRA/GetLines/'),
        editurl: '/CRA/EditModifyLine',
        emptyrecords: '',
        datatype: 'json',
        mtype: 'GET',
        colNames: ['Group', 'Description', 'Quantity'],
        colModel: [
      { name: 'Group', index: 'Group', width: 100, align: 'left' },
      { name: 'Description', index: 'Description', width: 400, align: 'left' },
      { name: 'Quantity', index: 'Quantity', width: 150, align: 'left', editable: true },
        pager: jQuery('#pgrLines'),
        rowNum: 10,
        rowList: [5, 10, 20, 50],
        sortname: 'Group',
        sortorder: "desc",
        viewrecords: true,
        caption: 'Core Group Lines',
        onSelectRow: function(id) {
            $('#tblCoreGroupLines').editRow(id, true);
            lastsel = id;
        },
        afterSubmit: function(response, postdata) {
            alert('got here');
        },
        postData: { craId: $('#CraId').val() }
    });

我尝试将较低的事件定义为 navControl 的一部分,但这也不起作用。内联编辑工作正常 - POST 成功并且结果返回,它只是永远不会遇到应该与之绑定的事件。我已经尝试了所有与 Quantity 字段更改相关的事件,但它们都不起作用。

我是否在正确的位置定义了事件?我错过了网格上的属性还是什么?

【问题讨论】:

    标签: javascript jquery asp.net-mvc jqgrid


    【解决方案1】:

    我认为您需要将属性参数中的afterSubmit 传递给editRow。

    因此,您需要像这样移动afterSubmit:

     .....
     onSelectRow: function(id) {
         $('#tblCoreGroupLines').editGridRow(id, { afterSubmit: function(response, postdata) {
               alert('got here');
            } 
         });
         lastsel = id;
    },
    ...
    

    关于 editGridRow 的文档在这方面提供了一些帮助。

    上面的示例会导致一个模态(因为这是唯一使用 afterSubmit 的地方)。如果您想在使用内联编辑成功更新后做某事,您应该能够在 onSelectRow 内部执行以下操作

     $('#tblCoreGroupLines').editGridRow(id,true, undefined, function(res) { 
        // res is the response object from the $.ajax call
        alert('success!!') 
     } ); 
    

    这是来自 js/grid.inlineedit.js 的 editRow 的方法签名

        editRow : function(rowid,keys,oneditfunc,succesfunc, url, extraparam, aftesarvefunc,errorfunc, afterrestorefunc) {
    

    【讨论】:

    • 我认为你在正确的轨道上。但是,该 editRow 语句曾经有两个参数 .editRow(id, true)。布尔值“true”参数发生了什么变化?没有它,单元格似乎不再提交。
    • 我希望避免弹出框。理想情况下,希望在网格中获得该行为以进行内联编辑。
    • 不客气。奇怪的是,内联和表单的方法信号是如此不同。
    【解决方案2】:

    您也可以在 editRow 方法中使用 aftersavefunc 事件来获取服务器响应,如果这是您唯一要查找的内容。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-01-18
      • 2012-01-11
      • 1970-01-01
      • 2011-05-05
      • 1970-01-01
      • 1970-01-01
      • 2011-04-04
      相关资源
      最近更新 更多