DataTable自动生成的序列号无法正常工作..适用于每个页面

时间:2015-03-10 10:37:18

标签: javascript datatable

DataTable分页程序没有显示连续的索引号......现在每页显示10个项目,第一页数据表序列号从1-10开始正确生成..但每页显示1到10个编号,需要显示第二页的连续编号,如11,12 ...我使用以下代码进行数据表。

任何帮助都会很明显,

谢谢

<script>

            $(document).ready(function(){
                var t = $("#table_details").DataTable({

                    "pagingType" : "full_numbers",
                    "processing" : true,
                    "searching"  : true,
                    "serverSide" : true,
                    "ajax" :{"url" : "../dataTable/serversideContacts.php",
                             "type": "post",
                             "data": { "uid" :'.$uid.',"gid" :'.$group_id.',"sid" :'.$site_id.'},

                            },

                    "columnDefs": [ {"searchable": false,"orderable": false,"targets": [0,3,4]} ],
                    "order": [[ 1, "asc" ]],
                    "language": {
              "info": "Showing page _PAGE_ of _PAGES_"
                          }

                });

                t.on( "order.dt search.dt processing.dt", function (){ 

                    t.column(0,{ search:"applied", order:"applied" }).nodes().each( function (cell, i) 
                    {cell.innerHTML = i+1; });
                }).draw();
            });
        </script>

2 个答案:

答案 0 :(得分:2)

答案基于以下内容:Alert the page no. on jQuery dataTables page change event

(假设per page = 10

dTable.on( 'order.dt search.dt processing.dt page.dt', function () {
    dTable.column(1, {search:'applied', order:'applied'}).nodes().each( function (cell, i) {
        cell.innerHTML = i+1;
        var info = table.page.info();
        var page = info.page+1;             
        if (page >'1') { 
            hal = (page-1) *10;  // u can change this value of ur page
            cell.innerHTML = hal+i+1;
        } 
    } );
} ).draw(); 

希望这有帮助。

答案 1 :(得分:0)

对于DataTables&gt; = 1.10.4,

"fnCreatedRow": function (row, data, index) {
                $('td', row).eq(0).html(index + 1);
            }

希望这会有所帮助:)