2015-11-02 16 views
5

Tôi đang cố gắng để làm cho Angularjs DataTable phía máy chủ pagination trong liên kết này https://l-lin.github.io/angular-datatables/#/serverSideProcessingAngularjs DataTable phía máy chủ pagination

Vì vậy, tôi sử dụng mã này

$scope.dtOptions = DTOptionsBuilder.newOptions() 
     .withOption('ajax', { 
        dataSrc: function(json) { 
        conole.log(json) 
        json['recordsTotal'] =json.length 
        json['recordsFiltered'] = json.length 
        json['draw']=1 
        conole.log(json) 
        return json; 
        }, 
       url: 'api/footestrecords', 
       type: 'GET' 
      }) 
     .withOption('processing', true) 
     .withOption('serverSide', true) 
     .withPaginationType('full_numbers'); 

tôi thêm recordsTotal, recordsFiltered và hàng bằng tay trong tham số dataSrc

và đây là dữ liệu json trước và sau khi thêm recordsTotal, recordsFiltered và hàng dữ liệu

json trước khi thêm

[Object, Object, Object, Object, Object, Object, Object, Object, 
Object,Object, Object, Object, Object, Object, Object, Object, Object, 
Object, Object, Object, Object, Object, Object, Object, Object, Object, 
Object, Object] 

json dữ liệu sau khi thêm

[Object, Object, Object, Object, Object, Object, Object, Object, 
    Object, Object, Object, Object, Object, Object, Object, Object, Object, 
    Object, Object, Object, Object, Object, Object, Object, Object, 
    Object,Object, Object, recordsTotal: 28, recordsFiltered: 28, draw: 1] 

các probelm là pagination không làm việc, bảng dữ liệu cho thấy tất cả dữ liệu trong một trang, và khi tôi bấm vào nút phân trang đã không có hành động.

định dạng
+0

bạn có thể khắc phục không? –

+0

Bạn đã thực hiện lỗi ở đây: 'conole.log' – zygimantus

Trả lời

1

Di .dataSrc và sử dụng tùy chọn này:

.withDataProp(function(json) { 
    console.log(json); 
    json.recordsTotal = json.response.total; 
    json.recordsFiltered = json.response.total; 
    json.draw = 1; 
    return json.response.data; 
}) 

Thay đổi json.response theo đối tượng của bạn.

Các vấn đề liên quan