单击下一个按钮时,服务器进程数据表不断出现

时间:2017-09-23 09:49:03

标签: javascript datatables angular-datatables

我使用datatable处理后端的大数据。在DTOptionsBuilder中,我使用withFnServerData方法从数据库中获取一系列数据。它从开始到限制解析了表中的所有内容。但下面的分页数始终是一个。似乎不工作,我只能使用左上角的数字过滤器,但不是我想要的。

控制器

SELECT channels.channel_name FROM `channels` 
JOIN channels_members on channels.id = channels_members.channel_id 
JOIN users on users.id = channels.user_id where channels.is_auto =1 
OR channels_members.is_admin =1 
OR channels_members.is_user =1 and users.id = 1 
GROUP By channels.id 

HTML

$scope.dtColumns = [
  DTColumnBuilder.newColumn('d', 'column').withOption('defaultContent', ""),
  DTColumnBuilder.newColumn('m', 'mukim').withOption('defaultContent', ""), ....
];

$scope.pageData = {
        total: 0
};

var get = function(sSource, aoData, fnCallback, oSettings){
      var draw = aoData[0].value;
      var order = aoData[2].value;
      var start = aoData[3].value;
      var length = aoData[4].value;

      var params = {
            start:start,
            limit:length
      };

      ValuationService.SearchValuation(params, function(result, response){
        if(result == true){
            var records = {
                    'draw': 0,
                    'recordsTotal': 0,
                    'recordsFiltered': 0,
                    'data': []
            };
            if(response.result){
                  records = {
                    'draw': draw,
                    'recordsTotal': response.total_data,
                    'recordsFiltered':response.result.length,
                    'data': response.result
                };
            }
            $scope.pageData.total = response.total_data;

            fnCallback(records);
        }
      });
}

$scope.dtOptions = DTOptionsBuilder.newOptions()
        .withFnServerData(get) // method name server call
        .withDataProp('data')// parameter name of list use in getLeads Fuction
            .withOption('processing', true) // required
            .withOption('serverSide', true)// required
            .withOption('paging', true)// required
            .withPaginationType('full_numbers')
        .withDisplayLength(10)
        .withOption('rowCallback', rowCallback)
         .withDOM('lrtip');

function rowCallback (nRow, aData, iDisplayIndex, iDisplayIndexFull) {
    $compile(nRow)($scope);
}

我想要什么

table.row-border.hover(datatable="", dt-instance="dtInstance",dt-columns="dtColumns", dt-options="dtOptions" style="overflow:auto;")

当前问题

The table below will show the number of pagination. I can click the next and previous. When I click next, it will call the API again to retrieve and parse another start to limit into table.

enter image description here

1 个答案:

答案 0 :(得分:0)

问题在于过滤器数据部分,因为我的数据已经过滤,没有显示所有数据。只需更改过滤后的记录,就可以解决问题。

records = {
     'draw': draw,
     'recordsTotal': response.total_data,
     'recordsFiltered':response.total_data, // Change total_data
     'data': response.result
};