PHP Datatable服务器端处理计数器列

时间:2015-10-30 08:18:16

标签: jquery datatable

我正在尝试为我的数据表创建一个计数器,但每次我点击下一页时,我都会得到上一页的数据。

任何人都有解决方案吗?这是我的JS:

var pTable = $('#users-table').DataTable({

        processing: true,
        serverSide: true,
        bFilter: false,
        ajax: {
            url: '{!! route('datatables.filter') !!}',
            data: function(d){ //these data will be passed to filter
                d.username = $('input[name=username]').val();
                d.email = $('input[name=email]').val();
                d.status = $('input[name=status]').val();
            }
        },
        "columnDefs": [ {
            "searchable": false,
            "orderable": false,
            "targets": 0
        } ],
        order: [[ 1, 'asc' ]],
        columns: [
            { data: null},
            { data: 'username', name: 'username' },
            { data: 'email', name: 'email' },
            { data: 'user_id', name: 'user_id' , 'visible': false},
        ],

    });

    pTable.on('order.dt search.dt page.dt', function () {
        var start = pTable.page.info().start;
        var info = pTable.page.info();
        pTable.column(0, {order:'applied'}).nodes().each( function (cell, i) {
            cell.innerHTML = start+i+1;
        } );
    } ).draw();

1 个答案:

答案 0 :(得分:0)

尝试将您的page.dt更改为draw.dt