2012-10-18 39 views
3

我正在使用Jquery datatables來構建表。我需要每行的行索引。但是當我切換到下一頁時,行索引重置爲1。 我需要行索引從第一頁最後一行繼續,意思是如果我的頁面大小是10,那麼第二頁第一行應該從11開始,而不是1. 我的問題與此圖像相同SAMPLE。 請幫我檢查我的代碼有什麼問題。非常感謝:)JQuery Datatables行索引不顯示根據頁面

var oTable = $('#myDataTable').dataTable({ 
       "bServerSide": true, 
       "bJQueryUI": true, 
       "bProcessing": true, 
       "sAjaxSource": sAjaxPage.toString(), 
       "sPaginationType": "full_numbers", 
       "fnRowCallback": function (nRow, aData, iDisplayIndex, iDisplayIndexFull) { 
        debugger; 
        var index = iDisplayIndexFull + 1; 
        $("td:first", nRow).html(index); 
        return nRow; 
       }, 
     "fnServerParams": function (aoData) { 
        aoData.push({ "name": "pTransactionDateFrom", "value": pTransactionDateFrom }); 
        aoData.push({ "name": "pTransactionDateTo", "value": pTransactionDateTo }); 
        aoData.push({ "name": "pTransactionNo", "value": pTransactionNo }); 
       }, 
       "aoColumns": [ 
         { 
          "bSort": false, 
          "bSearchable": false, 
          "bSortable": false, 
          "bFilter": false 
         }, 
         null, 
         null, 
         null, 
         null, 
         null, 
         null, 
         null 
        ] 
}); 
+0

似乎是工作。我使用了和你一樣的'fnRowCallback'。檢查[this](http://jsfiddle.net/qfqQN/) – bhb

+0

感謝您的幫助,但它仍然不起作用在我的頁面上。 :(我也使用jquery數據表版本1.9.4 – cjjack88

+0

是否有任何方法可以在javascript中獲得oTables.iDisplayStart值,我計劃通過** iDisplayStart + iDisplayIndexFull + 1獲取行索引; **。我搜索在谷歌,但不能得到它:): – cjjack88

回答

2

我找到了解決我的問題的方法。不是標準,但它的工作。 :)

"fnRowCallback": function (nRow, aData, iDisplayIndex, iDisplayIndexFull) { 

        var numStart = this.fnPagingInfo().iStart; 

        var index = numStart + iDisplayIndexFull + 1; 
        $("td:first", nRow).html(index); 
        return nRow; 
       }, 

DataTable中的API是http://datatables.net/plug-ins/api#fnPagingInfo

$.fn.dataTableExt.oApi.fnPagingInfo = function (oSettings) { 
    return { 
     "iStart": oSettings._iDisplayStart, 
     "iEnd": oSettings.fnDisplayEnd(), 
     "iLength": oSettings._iDisplayLength, 
     "iTotal": oSettings.fnRecordsTotal(), 
     "iFilteredTotal": oSettings.fnRecordsDisplay(), 
     "iPage": Math.ceil(oSettings._iDisplayStart/oSettings._iDisplayLength), 
     "iTotalPages": Math.ceil(oSettings.fnRecordsDisplay()/oSettings._iDisplayLength) 
    }; 
};