2016-04-27 69 views
1

傢伙我使用的jqGrid ......我只希望沒有首先選擇整排在點擊圖像上獲得該行的ID ..這裏是我的代碼獲得該行的ID上點擊

<script type="text/javascript"> 
 
    
 
$(document).ready(function() { 
 
    $("#jqGrid").jqGrid({ 
 
    url: 'data.json', 
 
    datatype: "json", 
 
    styleUI: "Bootstrap", 
 
    colModel: [{ 
 
     label: 'Order ID', 
 
     name: 'OrderID', 
 
     key: true, 
 
     width: 75, 
 
     hidden: true 
 
    }, { 
 
     label: 'From Date', 
 
     name: 'FromDate', 
 
     width: 150, 
 
     editable: true, 
 
     edittype: "text", 
 
     id: "ui-datepicker-div", 
 
     editoptions: { 
 
      dataInit: function(element) { 
 
       $(element).datepicker({ 
 
        autoclose: true, 
 
        format: 'yyyy-mm-dd', 
 
        orientation: 'auto bottom' 
 
       }); 
 
      }, 
 

 
     }, 
 
    }, { 
 
     label: 'To Date', 
 
     name: 'ToDate', 
 
     width: 150, 
 
     editable: true, 
 
     edittype: "text", 
 
     editoptions: { 
 
      dataInit: function(element) { 
 
       $(element).datepicker({ 
 
        autoclose: true, 
 
        format: 'yyyy-mm-dd', 
 
        orientation: 'auto bottom' 
 
       }); 
 
      }, 
 

 
     }, 
 
    }, { 
 
     label: 'Customer ID', 
 
     name: 'CustomerID', 
 
     width: 150 
 
    }, { 
 
     label: 'Ship Name', 
 
     name: 'ShipName', 
 
     width: 200 
 
    }, { 
 
     label: 'Row Data', 
 
     name: 'RowData', 
 
     align: 'center', 
 
     formatter: function() { 
 
      return "<img src='resources/icon.jpg' onclick='OpenDialog()' alt='Data Row' />"; 
 
      width = 15; 
 
     } 
 
    }, ], 
 
    loadonce: true, 
 
    ...... 
 
}); 
 

 
}); 
 

 
........... 
 

 
function OpenDialog() { 
 
var result = ""; 
 
var grid = $("#jqGrid"); 
 
var rowKey = grid.getGridParam("selrow"); 
 
rowData = grid.getLocalRow(rowKey); 
 
for (var item in rowData) { 
 
    if (item == 'RowData') { 
 
     break; 
 
    } 
 
    result += rowData[item] + ', '; 
 
} 
 
alert(result); 
 

 
}

任何幫助,請在如何只感謝點擊圖像??上..很多讓行的ID ..謝謝提前

回答

1

使用這個網站:

onclick='OpenDialog(this)' 

和在OpenDialog使用最接近的jquery方法:

function OpenDialog(element) { 
    var id = $(element).closest('tr').attr('id'); 
    ... 
}