2016-01-15 38 views
0

我需要在編輯之前檢索行內容或單元格內容,以便我可以將它傳遞給發佈數據。基本上我需要比較編輯前和編輯後的值並將它們發送到數據庫。這是我的代碼,但beforeEdit單元格沒有觸發。jqGrid比較前後單元格或行編輯值

Grid.jqGrid({ 
    url   : URL, 
    editurl  : UpdURL, 
    mtype  : "POST", 
    postData : {'action':'wk','ID':ID}, 
    datatype : "JSON", 
    page  : 1, 
    regional : lang, 
    beforeEditCell : getCellCurrentValue, 
    idPrefix : "w_", 
    colNames : WkColName[lang], 
    colModel : [ 
        { name: 'ID', width: 25, hidden: true }, 
        { name: 'c_ID', key:true, editable: true, width: 20, editrules : { required: true, integer:true, minValue:1} }, 
        ], 
    autowidth : true, 
    height  : 445, 
    rowNum  : 20, 
    caption  : GridCaption, 
    shrinkToFit : true, 
    sortorder : "asc", 
    hidegrid : false, 
    gridview : true, 
    pgbuttons : false, 
    pgtext  : null, 
    viewrecords : false, 
    pager  : GridPager, 
}) 
.inlineNav(GridPager,{edit: true, add: true, del: false, cancel: true, refresh : false, 
           editParams: {keys: true,extraparam: {'action':'wk', 'ID': ID, 'oldwk' : oldwkValue}}, 
           addParams: {position: 'last', 
               addRowParams:{ 
               keys:true, 
               extraparam:{'action':'wk','ID':ID}, 
                  successfunc: function() { 
                   var $self = $(this); 
                   setTimeout(function() { 
                    $self.trigger("reloadGrid"); 
                   }, 50); 
                  } 
               } 
              } 
          }); 
var lastWkselRowContent; 
var oldWkValue; 
function getCellCurrentValue(id) { 
    if (id && id !== lastWkselRowContent) { 
     oldWeekValue = Grid.jqGrid('getCell',id,'ID'); 
     lastWkselRowContent = id; 
     return oldWkValue; 
    } 
} 

回答

0

最簡單的方法可能是beforeSaveRow使用動態改變extraparam並添加額外的信息,您需要。您可以在editParamsaddRowParams中包含回調。 beforeSaveRow回調的前兩個參數是optionsrowidoptions包含extraparam屬性,您可以擴展更改的屬性。您會在savedRow內找到舊行,它是jqGrid的參數。我想你可以在savedRow[0].ID找到需要的信息。

beforeSaveRow: function (options, rowid) { 
    var p = $(this).jqGrid("getGridParam"); 
    // modify extraparam 
    options.extraparam.oldwk = p.savedRow[0].ID; 
    // to be exact one can search p.savedRow array 
    // for the item which have p.savedRow[i].id === rowid, 
    // but if only one row is editing at the same time then 
    // the array p.savedRow have only one element and 
    // p.savedRow[0] have the old values: c_ID and ID 
    // and p.savedRow[0].id === rowid 
} 
相關問題