如何找到kendo dataSource的长度?

时间:2016-04-12 18:40:59

标签: angularjs kendo-grid

我正在尝试查找kendo网格dataSource的长度,但我总是得到0作为回报。如何获得dataSource的总长度?我添加了Control服务,它是网格的dataSource。

ctrl.js

  $scope.alignedProcessesToControlGridOptions.dataSource = ControlRatingGridDataService.getAlignedProcessesToControlGrid($stateParams.controlId);
  var data = $scope.alignedProcessesToControlGridOptions.dataSource.data().length;
  console.log('GRID DATA', data);

DataService.js

getAlignedProcessesToControlGrid: function(controlKey) {
    var countNew = 0;
    return new kendo.data.DataSource({
        type: 'json',
        serverPaging: true,
        serverSorting: true,
        serverFiltering: true,
        transport: {
            read: function(options) {
                var gridSearchObject = {
                    skip: options.data.skip,
                    take: options.data.take,
                    pageSize: options.data.pageSize,
                    page: options.data.page,
                    sorting: options.data.sort,
                    filter: options.data.filter
                };
                return $http.post(
                    'app/control/rest/allAlignedProcessesToControl/' + controlKey, gridSearchObject).success(
                    function(data) {
                        countNew = data.totalCount;
                        options.success(data.resultDTOList);
                    });
            }

        },
        pageSize: 5,
        schema: {
            model: {
                id: 'riskInProcessKey',
                fields: {
                    processName: {
                        editable: false
                    },
                    epcfName: {
                        editable: false
                    },
                    erhName: {
                        editable: false
                    },
                    ctlGeolocationsText: {
                        editable: false
                    },
                    ctlPerformanceRatingText: {
                        editable: false
                    },
                    ctlEffectivenessRatingText: {
                        editable: false
                    }
                }
            },
            total: function() {
                return countNew;
            }
        }
    });
},

1 个答案:

答案 0 :(得分:0)

假设您的网格HTML看起来像......

 $("#grid").kendoGrid({
            dataSource: {
                // your datasource
            },
            dataBound: onDataBound
    });

dataBound事件创建一个函数...

function onDataBound(e) {
   console.log(e.sender.dataSource.view().length);
}