【问题标题】:Kendo Pager (pageable) is showing 'No items to display' even if the record are there即使记录在那里,Kendo Pager(可分页)也显示“没有要显示的项目”
【发布时间】:2017-05-17 09:12:57
【问题描述】:

我在这里使用带有 Angular-JS 的 Kendo-UI。

在剑道网格表上集成分页(可分页)时遇到问题,即使数据(记录)正确加载,它也会显示“没有要显示的项目”。

不知道有什么问题,任何帮助都会被占用......

以下是我用来加载/初始化数据网格的函数。

function getProjectsAtAGlance() {
                $scope.gridOptions = {
                    scrollable: false,
                    sortable: true,
                    pageable: {
                        pageSizes: [5, 10, 15, 20, 25, 50]
                    },
                    change: function (e) {
                        $scope.pageSize = $scope.gridOptions.dataSource.pageSize();
                    },
                    dataSource: {
                        serverPaging: true,
                        transport: {
                            read: function (options) {

                                $scope.options = options;

                                var filters = {
                                    skip: options.data.skip,
                                    take: options.data.take,
                                    sortBy: $scope.sortBy,
                                    projectGlanceIncludeArchived: $scope.includeArchivedProjects,
                                    projectGlanceExcludeProjectsWithNoBudgets: $scope.excludeProjectsWithNoBudgets
                                };

                                $http.post("/Home/ProjectsAtAGlanceReport", filters)
                                    .success(function (result) {
                                        var projects = result.projects;

                                        for (var i = 0; i < projects.length; i++) {
                                            var project = projects[i];
                                            project.startDate = moment(projects[i].startDate).format("L");
                                            project.endDate = moment(projects[i].endDate).format("L");
                                        }

                                        options.success(projects);

                                    })
                                    .error(function (error) {
                                        console.log(error);
                                    });
                            }
                        },
                        pageSize: $scope.pageSize,

                        schema: {
                            total: function (respose) {
                                return $scope.data;
                            },

                            model: {
                                fields: {
                                    name: {
                                        editable: false,
                                        nullable: true
                                    },
                                    resourceCount: {
                                        editable: false,
                                        nullable: true
                                    },
                                    clientName: {
                                        editable: false,
                                        nullable: true
                                    },
                                    startDate: {
                                        editable: false,
                                        nullable: true
                                    },
                                    endDate: {
                                        editable: false,
                                        nullable: true
                                    },
                                    projectId: {
                                        editable: false,
                                        nullable: true
                                    },
                                    projectedBudgetPercentage: {
                                        defaultValue: 100
                                    },
                                    defaultValue: {
                                        totalBudget: 0,
                                        totalHours: 0,
                                        burnedBudget: 0,
                                        burnedHours: 0,
                                        projectedBudget: 0,                                         
                                        projectedHours: 0,
                                        projectedHoursPercentage: 0,
                                        remainingBudget: 0,
                                        remainingBudgetPercentage: 0,
                                        remainingHours: 0,
                                        remainingHoursPercentage: 0
                                    }
                                }
                            }
                        }
                    },

                    columns: [
                        {
                            template: "<div class='name-column'>" +
                                "<p><a class='highlighted-blue' href='/Projects/ProjectAdmin/{{dataItem.projectId}}'>{{dataItem.name}}</a></p>" +
                                "<small>{{dataItem.clientName}}</small>" +
                                "<small ng-if=\"dataItem.startDate !== 'Invalid date'\">{{dataItem.startDate}} - {{dataItem.endDate}}</small>" +
                                "<small ng-if=\"dataItem.startDate === 'Invalid date'\"><i class='fa fa-exclamation-triangle text-danger'></i> Start date and end date are not defined.</small>" +
                                "<small>{{dataItem.resourceCount}} Resources</small></div>"

                        },
                        {
                            template: kendo.template($("#kendoProgressBarColumnTemplate").html())
                        },
                        {
                            template: "<accuracy-gauge-per-project accuracy='dataItem.accuracy'></accuracy-gauge-per-project>"
                        },
                        {
                            template:
                                "<p>{{dataItem.accuracy | percentage:0}} Accurate</p>" +
                                "<p>{{100-dataItem.accuracy | percentage:0}} Non Accurate</p>"
                        }
                    ]
                };
            }

这是一个输出 sn-ps 供参考。

【问题讨论】:

    标签: javascript angularjs kendo-ui pagination kendo-grid


    【解决方案1】:

    我认为pageSize 属性需要在dataSource 中声明,如下所示:

    dataSource: {
        serverPaging: true,
        transport: {... // transport options
        },
        pageSize: $scope.pageSize // before end of dataSource       
    },... // more grid stuff
    

    根据documentation,将您返回的内容从schema.total 更改为return response.total

    【讨论】:

    • 另外,resposeschema.total 中包含什么?这个函数不应该是return respose.total吗?
    • 是的 Sandman,你是对的,'schema.total' 有问题。我已经删除了“total: function (respose) {return $scope.data;}”来检查它现在工作正常。
    • 很高兴听到您成功了。如果它导致解决方案,请不要忘记投票并接受答案。 :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-31
    相关资源
    最近更新 更多