如何从jQuery dataTables获取分页信息

时间:2015-09-25 15:08:17

标签: javascript datatables

如何从jQuery DataTables中的分页信息240中获取这两个值:245Showing 240 to 245 of 744 entries

截图

我的代码:

ajax: function (data, callback, settings) {
    var out = [];
    filterModel.Take = THERE_MUST_BE_FIRST_VALUE
    filterModel.Skip = THERE_MUST_BE_SECOND_VALUE
    var promise = filterService.getElectricityData(filterModel);
    promise.then(function(data) {
        for (var i = 0; i < data.length; i++) {
            var model = [];
            for (var j = 0; j < data[i].length; j++) {
                model.push(data[i][j]);
            }
            out.push(model);
        }

2 个答案:

答案 0 :(得分:0)

使用page.info()获取有关该表的分页信息。

"ajax": function (data, callback, settings) {
   var api = new $.fn.dataTable.Api(settings);
   var info = api.page.info();

   filterModel.Take = info.start + 1;
   filterModel.Skip = info.end;

   // ... skipped ...
}

答案 1 :(得分:-1)

您可以通过不同方式访问

$.fn.dataTable.settings

// 240
var start = $.fn.dataTable.settings[0]._iDisplayStart;
// 5
var size  = $.fn.dataTable.settings[0]._iDisplayLength;
// 245
var end   = start + size;

jQuery选择器$("datatableId_info").text()

/Showing (\d+) to (\d+) of (\d+) entries/.exec("Showing 241 to 245 of 744 entries");
Array [ "Showing 11 to 20 of 57 entries", "11", "20", "57" ]