2012-05-29 71 views
0

我真的很困難,並且似乎無法使此工作。JQGrid - OndblClickRow事件來選擇所選行的字段值

基本上我有一個預訂表,例如

id bookref account fare 

1  BR1   101  10.00 

2  BR2   202  20.00 

我的Jqgrid顯示所有這些信息,我想要做的是獲取選擇行的bookref值。目前的功能我已經是:

ondblClickRow: function(rowid) 
    { 
     var grid = $('#bookings'); 
     var sel_id = grid.jqGrid('getGridParam', 'selrow'); 
     var myCellData = grid.jqGrid('getCell', sel_id, 'bookref'); 

     alert(myCellData); 

    }, 

當我雙擊第一行,我得到「BR1」返回這是正確的,如果我雙擊任何其他行我仍然得到「BR1」時,我應該得到「BR2 '如果第二行被點擊。

有人可以幫我這個嗎?將大規模感激

+1

爲什麼你使用'sel_id',而不是代替'rowid'參數的使用情況如何?如果你總是使用相同的'rowid'參數值,你應該驗證你是否正確填充了數據。在這種情況下,你可以在你的問題中包含jqGrid的更多完整定義(例如,使用'multiselect:true'可能會很有趣),幷包含測試數據(至少兩行數據)。 – Oleg

+0

嗯,我最初是使用下面的代碼,但我有同樣的問題, – nsilva

+0

ondblClickRow:功能(ROWID) \t \t { \t \t VAR rowData =新的Array(); \t \t \t rowData = $(「#bookings」)。getRowData(rowid); $(「#cp-bookings-dialog」)。dialog({hide:'slide',height:625,width:733,title:'Booking Reference:''+ rowData ['bookref']}); \t \t}, – nsilva

回答

4

如果你在我的代碼看到這裏,我在我的網格中也使用ondblClickRow。如果您看到此處,我將獲取所有行值並根據需要進行自己的更改,最後使用document.location.href加載作業詳細信息頁面。
我能夠對網格中的所有行執行此操作。

ondblClickRow: function(rowId) { 
    var rowData = jQuery(this).getRowData(rowId); 
    var jobNumber = rowData['jobNumber']; 
    var jobName = rowData['description']; 
    var jobCustomer = rowData['customerName']; 
    var jobStatus = rowData['jobStatus']; 
    jobName = jobName.replace(/&/g, "``"); 
    jobName = jobName.replace(/#/, "__"); 
    var aQryStr = "jobNumber=" + jobNumber + "&jobName=" + jobName + "&jobCustomer=" + jobCustomer; 
    console.log("./jobflow?token=view&" + aQryStr); 
    document.location.href = "./jobflow?token=view&" + aQryStr; 
}, 

如果你想看到我滿格代碼:

$("#jobsGrid").jqGrid({ 
     url:'../job_controller', 
     datatype: 'JSON', 
     mtype: 'POST', 
     pager: jQuery('#jobsGridPager'), 
     colNames:['Job #','Project','City', 'Rep', 'Status', 'Customer', 'Cust PO #', 'Rep. #'], 
     colModel :[ 
      {name:'jobNumber', index:'jobNumber', align:'left', width:50, editable:true,hidden:false, edittype:'text', 
        editoptions:{size:30,readonly:true},editrules:{edithidden:false,required:false}}, 
      {name:'description', index:'description', align:'left', width:150,hidden:false, editable:true, 
        editoptions:{size:20,readonly:false, alignText:'right'},editrules:{edithidden:true,required:true}}, 
      {name:'locationCity', index:'locationCity', align:'', width:90,hidden:false, editable:true, 
        editoptions:{size:20,readonly:false, alignText:'right'},editrules:{edithidden:true,required:true}}, 
      {name:'initials', index:'initials', align:'center', width:30,hidden:false, editable:true, 
        editoptions:{size:20,readonly:false, alignText:'right'},editrules:{edithidden:true,required:true}}, 
      {name:'jobStatus', index:'jobStatus', align:'center', width:60,hidden:false, editable:true, 
        editoptions:{size:20,readonly:false, alignText:'right'},editrules:{edithidden:true,required:true}}, 
      {name:'customerName', index:'customerName', align:'', width:150,hidden:false, editable:true, 
        editoptions:{size:20,readonly:false, alignText:'right'},editrules:{edithidden:true,required:true}}, 
      {name:'customerPONumber', index:'customerPONumber', align:'center', width:90, hidden:false, editable:true, 
        editoptions:{}, editrules:{edithidden:true,required:false}}, 
      {name:'code', index:'code', align:'center', width:40,hidden:false, editable:true, 
        editoptions:{size:20,readonly:false, alignText:'right'},editrules:{edithidden:true,required:true}} 
     ], 
     rowNum: 50, pgbuttons: true,  
     recordtext: '', 
     rowList: [50, 100, 200, 500, 1000], 
     viewrecords: true, 
     pager: '#jobsGridPager', 
     sortname: 'employeeId', sortorder: "asc", imgpath: 'themes/basic/images', caption: 'Jobs', 
     height:547, width: 1140,/*scrollOffset:0,*/ rownumbers:true, altRows: true, altclass:'myAltRowClass', rownumWidth: 45, 
     ondblClickRow: function(rowId) { 
      var rowData = jQuery(this).getRowData(rowId); 
      var jobNumber = rowData['jobNumber']; 
      var jobName = "" + rowData['description']; 
      var jobCustomer = rowData['customerName']; 
      var jobStatus = rowData['jobStatus']; 
      jobName = jobName.replace(/&/g, "``"); 
      jobName = jobName.replace(/#/, "__"); 
      var aQryStr = "jobNumber=" + jobNumber + "&jobName=" + jobName + "&jobCustomer=" + jobCustomer; 
      console.log("./jobflow?token=view&" + aQryStr); 
      document.location.href = "./jobflow?token=view&" + aQryStr; 
     }, 
     jsonReader : { 
      root: "rows", 
      page: "page", 
      total: "total", 
      records: "records", 
      repeatitems: false, 
      cell: "cell", 
      id: "id", 
      userdata: "userdata" 
     } 
    }).navGrid('#jobsGridPager', add:false,edit:false,del:false,refresh:false,search:false} 
    ); 
+0

比你,那個我正在尋找! – Houari

1

沒有用selrow,但是這是沒有事件的行,併發可能會失敗

檢查:

ondblClickRow: function(rowid) 
{ 
    var grid = $('#bookings');  
    var myCellData = grid.jqGrid('getCell', rowid, 'bookref'); 
    alert(myCellData); 
}