2015-05-11 26 views
3

通過使用角度智能表,我如何通過使用偏移值來獲得結果集。 例如,我在數據庫使用智能表的angularjs分頁

  1. 首先我需要從數據庫中獲得20條記錄,並在每頁上顯示只有10個項目100個記錄。
  2. 點擊第三頁之後,需要查詢數據庫(服務電話),並獲得另外20 records..etc(但不包括服務器徵集第2頁)

我使用智能表管/ AJAX插件來顯示記錄。

如何使用這個來實現。

<div class="table-container" ng-controller="pipeCtrl as mc"> 
      <table class="table" st-pipe="mc.callServer" st-table="mc.displayed"> 
       <thead> 
       <tr> 
        <th st-sort="id">id</th> 
        <th st-sort-default="reverse" st-sort="name">name</th> 
        <th st-sort="age">age</th> 
        <th st-sort="saved">saved people</th> 
       </tr> 
       <tr> 
        <th><input st-search="id"/></th> 
        <th><input st-search="name"/></th> 
        <th><input st-search="age"/></th> 
        <th><input st-search="saved"/></th> 
       </tr> 
       </thead> 
       <tbody ng-show="!mc.isLoading"> 
       <tr ng-repeat="row in mc.displayed"> 
        <td>{{row.id}}</td> 
        <td>{{row.name}}</td> 
        <td>{{row.age}}</td> 
        <td>{{row.saved}}</td> 
       </tr> 
       </tbody> 
       <tbody ng-show="mc.isLoading"> 
       <tr> 
        <td colspan="4" class="text-center"><div class="loading-indicator"></div> 
        </td> 
       </tr> 
       </tbody> 
       <tfoot> 
       <tr> 
        <td class="text-center" st-pagination="" st-items-by-page="5" colspan="4"> 
        </td> 
       </tr> 
       </tfoot> 
      </table> 
     </div> 

http://lorenzofox3.github.io/smart-table-website/

代碼在Plunker

http://plnkr.co/edit/wzUHcc9PBF6tzH8iAEsn?p=preview

回答

0
  1. 設置頁面大小至10

  2. 維護服務等級陣列對象(VAR fetchedData)對於從s中獲取的行erver。

  3. 如果所需數量的數據在客戶端不可用,則只調用服務器。

  4. 始終從fetchedData過濾分頁數據。

在你的服務中就像這樣。

var fetchedData = []; 

    function getPage(start, number, params) { 

     if (fetchedData.length < (start + number)) { 
      //get the next 20 rows from the server and add to fetchedData; 
     } 

     var filtered = params.search.predicateObject ? 
      $filter('filter')(fetchedData, params.search.predicateObject) : 
      fetchedData; 
     //rest of the logic