2016-08-17 82 views
0

我需要帮助,我的分页代码(http://plnkr.co/edit/Jv12fcBzm3lvZFqHqDJm?p=preview智能表分页不起作用

我的数据是巨大的(> 1000K行)。我只想为可见记录提出请求(每页50行)。每当用户更改排序或更改页面时,我都会请求REST服务调用。

在我的代码中,我用$ timeout替换$ http.post()来简化示例。

angular.module('app',['smart-table']) 
    .controller('mainCtrl',['Resource', function (service) { 
    var ctrl = this; 
    this.rowCollection = []; 
    this.totalMatched = 0; 
    this.totalExecutionTime = 0; 
    this.paginationStart = 0; 

    this.callServer = function callServer(tableState) { 
     ctrl.isLoading = true; 
     var pagination = tableState.pagination; 
     console.log(pagination.number); 
     var start = pagination.start || 0; 
     var number = pagination.number || 5; 

     service.getPage(start, number, tableState).then(function (result) { 
     var tstamp = new Date().getTime(); 
     console.log('Requesting page: '+start+', '+number+','+tstamp); 
     ctrl.rowCollection = result.data.items; 
     ctrl.totalMatched = result.data.total; 
     ctrl.paginationStart = start; 
     tableState.pagination.numberOfPages = result.numberOfPages;//set the number of pages so the pagination can update 
     ctrl.isLoading = false; 
     }); 
    }; 
    }]) 
    .factory('Resource', ['$q', '$filter', '$timeout', '$http', function ($q, $filter, $timeout, $http) 
    { 
    function getPage(start, number, params) { 

     var deferred = $q.defer(); 
    $timeout(function() { 
      deferred.resolve({ 
      data: {total:8000, items:[{message:'foo',messagetime:'2016-01-01'},{message:'foobis',messagetime:'2016-02-02'}]}, 
      numberOfPages: Math.ceil(1000/number) 
      }); 
     }, 1500); 


     return deferred.promise; 
     } 

     return { 
     getPage: getPage 
     }; 
    } 
    ]); 

我在做什么错?感谢您的帮助。

回答

1

在的script.js,就应该更换:

ctrl.rowCollection = result.data.items;  

通过

ctrl.displayedCollection = result.data.items; 

这是因为在你的表标签,你所用的ST表= “main.displayedCollection” 和NG- repeat =“main.displayedCollection中的项目”。

+0

谢谢,我注意到,我不必一起使用st-safe-src和st-pipe。我删除了st-safe-src并开始工作。 – zuko