在数据表中过滤索引-2到索引+ 2

时间:2017-04-12 17:41:35

标签: php jquery datatables

我目前正在显示返回玩家排名并突出显示当前玩家行的表格。我想要实现的是让我们说5行显示并将当前玩家置于中心位置。

如果当前玩家排名为100,我想显示玩家排名98到102.目前它将显示排名1到5。

我找不到想要以我的结果为中心的#34;目前的球员排名。

我的当前表格显示为以下代码:

$.ajax({
    url: "myController/getDataTable",
    method: 'post',
    dataType: 'json',
    success: function (values) {
        var table = $('#myTableLeaderboard').DataTable({
            paging: true,
            pageLength: 5,
            sort: true,
            searching: true,
            data: values['data'],
            ordering: true,
            aoColumns: [
                { "data": "ranking" },
                { "data": "cash" },
                { "data": "staff_count" }
                // more columns...
            ],
            "createdRow": function ( row, data, index ) {
                $currentUserId = $('#currentUserId').attr('value');
                if ( data.id_player == $currentUserId ) {
                    $('td', row).addClass('bold');
                }
            }
        });
        $('#myTableLeaderboard_filter').switchClass( 'dataTables_filter', 'dataTables_filter_show' ); 
    }
});

我的服务器端PHP函数返回两个数组,一个包含表的数据,另一个变量包含当前的玩家等级:

{"data":
    [{"cash":"606, "id_player":"61","staff_count":null,"ranking":1},
    {"cash":"30","id_player":"63","staff_count":null,"ranking":2},
    ...more players....],
"current_id_player":"67",
"current_player_ranking":3
}

我查看了Custom filtering - range search页面,但我不确定我应该查看什么以及如何处理它。

最后,启用了分页功能,因此如果播放器导航到另一个页面,结果将无法“居中”#34;在他身上了。

1 个答案:

答案 0 :(得分:0)

我找到了添加的解决方案:

displayStart: values.current_player_ranking-2,

使用jumpToData插件

完成
$('#myTableLeaderboard thead').on('click', 'th', function () {   
    table.page.jumpToData( $currentUserId, 9 );
} );
table.page.jumpToData( $currentUserId, 9 );
相关问题