2014-05-15 8 views
0

我有兩個jqgrid如下所示。Jqgrid:顯示選定的行數據到另一個網格

我想將選定的行從$("#grid")傳遞到$("#cmehoursgrid")

我寫了第一個網格數組的代碼。該數組是arrID。

但是..如何將它傳遞給第二個網格按鈕單擊?

第一格是$("#grid")

$("#grid").jqGrid({ //set your grid id 
        url: 'getSearchedUserDetails', //insert data from the data object we created above 
        datatype: 'json', 
        multiselect: true, 
        height :'auto', 
        colNames:['ID','First Name','Last Name','Email','Address','City','State','Zip','Phone','Licence State','Degree title','NPI','Total Credits Completed','Total Credits Required','%Completed','Course Expiration'], //define column names 
        colModel:[ 
        {name:'id', index:'id', key: true,width: 80}, 
        {name:'firstName', index:'first_name',key: true}, 
        {name:'lastName', index:'last_name', key: true}, 
        {name:'email', index:'email', key: true,width: 260}, 
        {name:'address', index:'address', key: true,width: 260}, 
        {name:'city', index:'city', key: true}, 
        {name:'state', index:'state', key: true}, 
        {name:'zip', index:'zip', key: true}, 
        {name:'phone', index:'phone', key: true}, 
        {name:'license_state', index:'license_state', key: true}, 
        {name:'degree_title', index:'degree', key: true}, 
        {name:'npi', index:'npi', key: true}, 
        {name:'tcc', index:'id', key: true}, 
        {name:'tcr', index:'id', key: true}, 
        {name:'Completed', index:'id', key: true}, 
        {name:'coursExpiration', index:'id', key: true} 
        ], //define column models 
        pager: '#pager', //set your pager div id 
        sortname: 'id', //the column according to which data is to be sorted; optional 
        viewrecords: true, //if true, displays the total number of records, etc. as: "View X to Y out of Z」 optional 
        sortorder: "asc", //sort order; optional 
        rowNum: 20, 
        caption:"Searched Participants", //title of grid 
        onSelectRow: function (rowid, e) {   //onSelectRow event 

         $('.cbox').each(function(){ 
          if($(this).attr('checked') == 'checked'){      
           var name = $(this).attr('id'); 
           var id = $('#'+name).closest('tr.jqgrow').attr('id'); 
           var id = $('#'+name).closest('tr.jqgrow').attr('id'); 
           var strFirstName = $("#grid").getCell(id,"firstName"); 
           var strLastName = $("#grid").getCell(id,"lastName"); 
           var intNpi = $("#grid").getCell(id,"npi"); 
           //alert(firstName); 
           arrID.push({ 
            id : id, 
            firstName : strFirstName, 
            lastName : strLastName, 
            npi : intNpi 
           });      
          } 
         }); 
         if(arrID.length == 1) { 
          $('.editProfile').removeAttr('disabled'); 
          $('.addCmeHours').attr('disabled', false); 
          $('.messageUser').attr('disabled',false); 
         } 
         if(arrID.length > 1) { 
          $('.editProfile').attr('disabled', true); 
          $('.addCmeHours').attr('disabled', false); 
          $('.messageUser').attr('disabled',false); 
         } 
         //alert(arrID.toSource()); 
         $('#selectedUser').val(arrID); 
        }, 
}); 

和第二格柵是$("#cmehoursgrid")

$("#cmehoursgrid").jqGrid({ //set your grid id 
        // url: 'getSearchedUserDetails', //insert data from the data object we created above 
        datatype: 'local', 
        multiselect: true, 
        colNames:['ID','First Name','Last Name','NPI'], //define column names 
        colModel:[ 
        {name:'id', index:'id', key: true,width:50}, 
        {name:'firstName', index:'fName',key: true,width:50}, 
        {name:'lastName', index:'lName', key: true,width:50}, 
        {name:'npi', index:'npi', key: true,width:50}, 
        ], //define column models 
        pager: '#cmehourspager', //set your pager div id 
        multiSort:true, 
        sortable:true, 
        loadonce :true, 
        rownum:5, 
        width:710, 
        height:300, 
        scrollOffset: 1, 
        shrinkToFit:true, 
        sortname: 'id', //the column according to which data is to be sorted; optional 
        viewrecords: true, //if true, displays the total number of records, etc. as: "View X to Y out of Z」 optional 
        gridview: true, 
        sortorder: "desc", //sort order; optional 
        caption:"Update CME Hours" //title of grid  
}); 

回答

0

看好jqGrid demos我們能找到的一個例子,你想要什麼:

for(var i=0;i<=arrID.length;i++) 
    jQuery("#cmehoursgrid").jqGrid('addRowData',i+1,arrID[i]); 
+0

謝謝lucasdc其working.But現在的問題是第一行添加兩次該做什麼。 – Abhijit

+0

您是否嘗試打印陣列內容?在循環之前,嘗試'console.log(arrID)'並查看你的控制檯,看看問題出在你的數組中還是循環使用 – lucasdc

+0

問題是我現在錯誤的數組名稱現在我的問題已解決 – Abhijit

相關問題