2012-04-10 121 views
1

我在cellEdit模式下有一個jgGrid。我需要獲取當前rowid,以進行一些進一步處理(根據其他值將單元格設置爲只讀)。我無法找到一個方法,我試過的事件不會觸發。jqGrid獲取當前rowid

網格的定義:

var curRowId = -1; 

    $("#grid").jqGrid({ 
     datatype: 'json', 
     mtype: 'GET', 
     colNames: ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's',], 
     colModel: [ 
      { name: 'a', index: 'a', width: 30, formatter: 'checkbox', edittype: 'checkbox', editable: true }, 
      { name: 'b', index: 'b', width: 30, formatter: 'checkbox', edittype: 'checkbox', editable: true }, 
      { name: 'c', index: 'c', width: 70, formatter: 'date', editable: true, editrules: { required: true }, editoptions: { dataInit: function (elem) { $(elem).datepicker(); } } }, 
      { name: 'd', index: 'd', width: 65, editable: true, formatter: 'date', formatoptions: { srcformat: 'H:i:s', newformat: 'ShortTime' }, editrules: { time: true} }, 
      { name: 'e', index: 'e', width: 80, edittype: 'select', editable: true, formatter: 'select' }, 
      { name: 'f', index: 'f', width: 100, editable: true }, 
      { name: 'g', index: 'g', width: 80, editable: true }, 
      { name: 'h', index: 'h', width: 80, editable: true, editrules: { maxValue: 50} }, 
      { name: 'i', index: 'i', width: 120, edittype: 'select', editable: true, formatter: 'select' }, 
      { name: 'j', index: 'j', width: 200, edittype: 'select', editable: true, formatter: 'select' }, 
      { name: 'k', index: 'k', width: 70, edittype: 'select', editable: true, formatter: 'select' }, 
      { name: 'l', index: 'l', width: 70, editable: true, editrules: { maxValue: 10} }, 
      { name: 'm', index: 'm', width: 25, editable: false }, 
      { name: 'n', index: 'n', width: 70, editable: true, editrules: { integer: true, maxValue: 999999 }, formatter: formatPosition, unformat: unformatPosition }, 
      { name: 'o', index: 'o', width: 25, editable: true, editrules: { custom: true, custom_func: chkLongitudTecken} }, 
      { name: 'p', index: 'p', width: 80, editable: true, editrules: { integer: true, maxValue: 999999 }, formatter: formatPosition, unformat: unformatPosition }, 
      { name: 'q', index: 'q', width: 80, edittype: 'select', editable: true, formatter: 'select' }, 
      { name: 'r', index: 'r', width: 100, editable: true, editrules: { maxValue: 50} }, 
      { name: 's', index: 's', width: 65, edittype: 'select', editable: true, formatter: 'select' }, 
     ], 
     cellEdit: true, 
     cellsubmit: "clientArray", 
     sortname: 'Datum', 
     sortorder: 'desc', 
     shrinkToFit: false, 
     viewrecords: true, 
     gridview: true, 
     beforeCellEdit: function (id) { 
      curRowId = id; 
      alert("Here: " + curRowId); 
     }, 
     onSelectRow: function (id) { 
      curRowId = id; 
      alert("test: " + curRowId); 
     }, 
     height: 400, 
     caption: 'My Cap' 
    }); 

你可以看到我已經在上面的代碼嘗試的事件。

我需要的ID,這樣我以後會做這樣的事情:

$("#grid").setColProp("k", { 
    editoptions: { 
     value: data.opPadrag, 
     dataEvents: [{ 
      type: 'change', 
      fn: function (e) { 
       alert(e.currentTarget.value); 
       $(e).addClass("not-editable-cell"); 
      } 
     }] 
    } 
}); 

回答

11

找到了解決辦法:

var selr = jQuery('#grid').jqGrid('getGridParam', 'selrow'); 
0
jQuery('#grid').jqGrid('getGridParam', 'selrow') 

會給用作列數據行ID「鍵」。如果「key」屬性沒有設置爲特定的網格列,那麼將返回正確的行ID。