2016-08-17 36 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