2017-02-16 23 views
0

enter image description here我們在jqgrid 4.3中使用了下面的代碼。現在我升級到4.13.6。下面的代碼在4.3中工作,但在4.13,它返回false ...任何幫助,請...free-jqgrid:getLocalRow在free中返回false -jqgrid4.13.6

var grid = $("#myGrid").jqGrid('getRowData'); 
$.each(grid, function(key, value) { 
    selectedRow = key+1; 
    var rowData = $("#myGrid").jqGrid('getLocalRow', selectedRow); 
}); 

我沒有使用任何ID卻使我的網格。數據類型:json,rownumbers:true。

當我調試時,我看到每行的ID是'jqg41','jqg42'等...有時它是'jqg61','jqg62'等...這是一個隨機數字'jqg'

更多的代碼(但尚未完成代碼)後

$grid.jqGrid({ 
        datatype: 'json', 
        url: 'myUrl/byFileId.do?custId='+custId, 
        mtype: 'GET', 
        ajaxSubgridOptions: { async: false }, 
        colNames:[ col1, col2 ...], 
        colModel:[  
         . . . 
         . . . 
         . . . 
        ], 
        headertitles:true, 
        rowNum:999, 
        rowList:[], 
        pager: '', 
        records: 1000, 
        pgbuttons : false, 
        viewrecords : false, 
        pgtext : null, 
        pginput : false, 
        gridview:true, 
        ignoreCase:true, 
        rownumbers:true, 
        sortname: 'invdate', 
        viewrecords: true, 
        sortorder: 'desc', 
        multiselect: true, 
        caption: "Customer Search Result", 
        height: '100%', 
        editurl: 'clientArray', 
        autoencode: true, 
        loadonce: true, 
        multiselectWidth: 30, 
        width: rmtPageTitleWidth, 
        viewsortcols : [true,'vertical',true], 
        onSortCol: function (index, idxcol, sortorder) { 
         rowIdAndNoOfRowPair = []; 
         if (this.p.lastsort >= 0 && this.p.lastsort !== idxcol 
           && this.p.colModel[this.p.lastsort].sortable !== false) { 
          $(this.grid.headers[this.p.lastsort].el).find(">div.ui-jqgrid-sortable>span.s-ico").show(); 
         } 
        }, 

enter image description here

+0

對不起,但你發佈的代碼是絕對錯誤的。如果'key'是rowid,那麼'key + 1'不是。它做什麼外殼?您是否需要獲取**所選行的數據或網格的所有本地數據?爲什麼你不指定rowid?您使用哪些數據和哪個網格?順便說一下,我在你之前的問題中回答了你的建議,在'customerId'列中設置'key:true'屬性,通知jqGrid使用'customerId'列中的值作爲rowid。 **你的代碼仍然錯誤,你應該解釋,應該怎麼做。** – Oleg

+0

我建議你閱讀[文章](https://free-jqgrid.github.io/getting-started/index.html#the_first_grid ),我在那裏解釋什麼是rowid。看到[圖片](https://free-jqgrid.github.io/getting-started/index.html#grid-internal-div)和下面的解釋。 – Oleg

+0

@Oleg:在jqgrid 4.3中,'key'總是給我0,但行的id從'1'開始。這就是我爲什麼要做「key + 1」的原因,現在到第二個問題,我不能讓客戶id爲key = true,因爲我可以在網格中擁有多個相同id的客戶。通過每一行(選擇和非選擇)並獲取數據,然後我可以將這些數據的邏輯應用於JavaScript,然後發送到後端。現在我想知道爲什麼它創建行的id爲'jqg <一些隨機數> – SKumar

回答

0

你可以使用

var localData = $("#myGrid").jqGrid("getGridParam", "data"); 

將所有本地數據作爲數組獲取。它是參考到jqGrid的內部數據。

更新:如果電網是排序或篩選本地,並希望得到在同一順序的所有行的數據,那麼你應該得到lastSelectedData參數,而不是data。您可以在從服務器加載後,通過使用forceClientSorting: true jqGrid的參數以及loadonce: true強制對本地數據進行排序。

演示https://jsfiddle.net/OlegKi/akv51mdq/演示lastSelectedData在沒有id信息的本地數據的情況下。另一個演示https://jsfiddle.net/OlegKi/Ljejoh21/與從服務器一次加載的數據完成相同。