javascript - 如何在 Kendo 网格列中显示相关外键数据

标签 javascript angularjs kendo-ui kendo-grid

我有一个剑道网格,它由 Angular Controller 控制:

<div>
    <kendo-grid options="mainGridOptions" k-data-source="gridData">
    </kendo-grid>
</div>

更新 正在加载数据,但未渲染网格。 (我也遇到了术语不匹配的情况,并将部门视为状态。

"use strict";
angular.module("tenderApp")
.controller("tenderCtrl", ["$scope", "adalAuthenticationService", "tenderSvc", "$q", function ($scope, adalService, tenderSvc, $q) {
    $scope.mainGridOptions = null;
    $scope.gridSource = null;
    $scope.statusData = null;

    function loadStatusData() {
        return tenderSvc.getSector()
            .then(function(sector) {
                $scope.sectorData = sector.data.map(function (obj) {
                    return {
                        text: obj.bezeichnung,
                        value: obj.id
                    };
                });
                return $scope.sectorData;
            });
    }

    function loadGridSource(result) {
        return tenderSvc.getItems()
            .then(function (res) {
                $scope.gridSource = res.data;
                return res.data;
            });
    }

    loadStatusData()
        .then(loadGridSource)
        .then(function (res) {
            //both properties are available at this point
            console.log($scope.gridSource);
            console.log($scope.sectorData);
            $scope.gridData = new kendo.data.DataSource({
                transport: {
                    read: function (e) {
                        e.success($scope.gridSource);
                    },
                    //...
                },
                //...
            });
            $scope.mainGridOptions = {
                toolbar: ["excel"],
                dataSource: $scope.gridData,
                columns: [
                    { field: "sektor", title: "Sektor", values: $scope.sectorData },
                    { command: ["edit"], title: "Aktionen", width: "120px" }
                ]
            };

        });
}]);

问题是,应该填充网格的最后一个调用无法正常工作。 console.log 调用显示数据已加载,但网格未显示。

最佳答案

很好,现在我向你学习如何进行链接。至于你的问题,我们不需要使用transport/read。相反,我们可以单独加载数据并将其设置到网格 dataSource 中,如下所示。请注意,请不要将 k-data-source="gridData" 放入网格 html 属性中,因为您已有网格选项。

HTML:

    <div><kendo-grid options="mainGridOptions" k-data-source="gridData">
    </kendo-grid></div>

JS:

"use strict";
angular.module("tenderApp")
.controller("tenderCtrl", ["$scope", "adalAuthenticationService", "tenderSvc", "$q", function ($scope, adalService, tenderSvc, $q) {
    $scope.mainGridOptions = null;
    $scope.gridSource = null;
    $scope.statusData = null;

    $scope.mainGridOptions = {
        dataSource: new kendo.data.DataSource(),
        toolbar: ["excel"],
        columns: [
            { field: "sektor", title: "Sektor", values: $scope.sectorData },
            { command: ["edit"], title: "Aktionen", width: "120px" }
        ]
    };

    function loadStatusData() {
        return tenderSvc.getSector()
            .then(function(sector) {
                $scope.sectorData = sector.data.map(function (obj) {
                    return {
                        text: obj.bezeichnung,
                        value: obj.id
                    };
                });
                return $scope.sectorData;
            });
    }

    function loadGridSource(result) {
        return tenderSvc.getItems()
            .then(function (res) {
                $scope.gridSource = res.data;
                return res.data;
            });
    }

    loadStatusData()
        .then(loadGridSource)
        .then(function (res) {
            $scope.mainGridOptions.dataSource.data($scope.gridSource);
        });
}]); 

关于javascript - 如何在 Kendo 网格列中显示相关外键数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37727231/

相关文章:

javascript - 如何更改我搜索的文本颜色?

javascript - Highstock 标题和副标题重叠

javascript - 将 Mongoose 播种脚本变成 promise

javascript - ionic.bundle.js 分解为单独的导入

javascript - ng-model 数据 bing 无法正常工作

javascript - 网格中的 Kendo DropDownList 在选择后才绑定(bind)

javascript - JSF 在 f :ajax 之后执行 javascript

javascript - 切换组中的所有 Angular 复选框

javascript - 在 Kendo Grid 中,当用户在 "items per page"下拉列表中选择特定值时如何添加警报?

c# - Kendo Grid 将所有数据打印到 Excel,而不仅仅是可见数据