2015-10-06 15 views
0

我想用遠程數據虛擬化的Kendo網格。我還需要爲transport.read屬性創建一個自定義方法。使用自定義transport.read方法進行網格遠程數據虛擬化?

我的柵配置是這樣的:

$(document).ready(function() { 
 
       $("#grid").kendoGrid({ 
 
        dataSource: { 
 
         serverPaging: true, 
 
         serverSorting: true, 
 
         pageSize: 100, 
 
         transport: { 
 
          read: function (options) { 
 

 
           // Get the template items, which could be products, collections, blogs or articles 
 
           getTemplateItems().then(function (data) { 
 

 
            options.success(data); 
 
           }); 
 
          } 
 
         } 
 
        }, 
 
        schema: { 
 
         total: function(response) { 
 

 
          return 2000; 
 
         } 
 
        }, 
 
        height: 543, 
 
        scrollable: { 
 
         virtual: true 
 
        }, 
 
        sortable: true, 
 
        columns: [ 
 
            { field: "title", title: "Title" } 
 
        ] 
 
       }); 
 
      }); 
 

 

 
      function getTemplateItems() { 
 

 
       var deferred = $q.defer(); 
 

 
       smartseoEntityMapping.getEntityInfo({ mappedEntityType: mappedEntityType.Product }).$promise.then(function (data) { 
 

 
        deferred.resolve(data); 
 
       }); 
 

 
       return deferred.promise; 
 
      }

的問題是,當電網初始化讀方法只調用一次。當滾動到達當前可見集合中的最後一個項目時,它不會被調用。

我懷疑是電網需要的項目總數,但我不知道如何設置項目的總數。設置schema.total屬性的方法不起作用,因爲該方法從不調用。

所以我想問問你,是這樣的情況可能在所有的,有一個自定義transport.read方法,它需要被稱爲每次獲得數據的下一個頁面的虛擬化工作?

爲什麼我使用自定義閱讀?好吧,我不能只設置一個網址爲transport.read屬性,因爲我的遠程調用通過angularjs資源製成,包括設置認證等..

回答

2

模式是劍道數據源的屬性。它看起來像你在數據源之外。

應該是:

$("#grid").kendoGrid({ 
       dataSource: { 
        serverPaging: true, 
        serverSorting: true, 
        pageSize: 100, 
        transport: { 
         read: function (options) { 

          // Get the template items, which could be products, collections, blogs or articles 
          getTemplateItems().then(function (data) { 

           options.success(data); 
          }); 
         } 
        }, 
        schema: { 
         total: function(response) { 

          return 2000; 
         } 
        } 
       }, 

       height: 543, 
       scrollable: { 
        virtual: true 
       }, 
       sortable: true, 
       columns: [ 
           { field: "title", title: "Title" } 
       ] 
      });