2015-09-28 358 views
2

我正在网格内使用下拉菜单。我打算根据下拉列的更改值更改其他列的值。我的代码如下所示JQGrid'Change'dataevent在更改函数内更改gridrow数据后不会触发

dataEvents: [ 
    { 
    type: 'change', 
    fn: function (e) { 
     var row = $("#Grid").closest('tr.jqgrow'); 
     var rowId = $("#Grid").jqGrid('getGridParam', 'selrow'); 
     //alert(rowId); 
     var rowData = jQuery('#Grid').getRowData(rowId); 
     rowData.ProductID = e.target.value; 
     //alert(rowData.ProductID); 
     $("#Grid").jqGrid('collapseSubGridRow', rowId); 
     rowData.SelectedOptions = rowData.ProductID + "------"; 
     jQuery('#Grid').setRowData(rowId, rowData); 
    } 
    } 
] 

更改事件在编辑模式下仅触发一次。如果我反复更改下拉值,则事件不会被触发。我尝试了代码内没有任何代码的变化功能,它运行良好。之后,我发现setRowData函数导致了问题。如果我注释掉setRowData行,那么它工作正常。

我不确定这种行为。任何帮助或建议? 感谢提前:)

+0

我使用的数据类型: '本地'网格。 –

+0

我无法找出这种行为的真正原因,但我使用setCell()函数来更改相应的行数据并且它工作。如果有人有任何补充的答案,请回复:) –

回答

0

我们已经得到了同样的问题整理出来,可以帮助别人,因为它的简单:

所以整个事情是这样的:

{ name: 'STOP', index: 'STOP', width: 30 ,editable: true,edittype: 'select',editoptions:{ 
          value: getStopLookup(), 
          dataEvents: [{type: 'change', 
           fn: function (e) { 
            // var rowid = e.target.id; 
            var row = $(e.target).closest('tr.jqgrow'); 
            var rowid = row.attr('id'); 
            jQuery(grid_selector).saveRow(rowid, 
             { 
              succesfunc: function (response) 
              { 
               return true; 
              }, 
              url: '@Url.Action("UpdateStop", "Route")', 
              mtype: "POST", 
              aftersavefunc:function (response) 
              { 
               ReloadGrid('RoutingDataGrid'); 
              }, 
             }); 
           } 
          }] 
         }},