Binding kendo ui grid columns headers to the scope in AngularJs

痞子三分冷 提交于 2019-12-25 12:47:15

问题


I'm using a kendo ui grid, and I want to bind the columns headers to a json file, instead of specifying it directly in the controller.

I created a function that successfully retrieves the array from the json file, and populate the scope:

        function returnColumns(){
            $http.get('app/data/headers.json')
                    .then(function(res){
                        $scope.myHeaders = res.data;
                    });
        }
        returnColumns();

And in the grid's options I'm referring the columns to that variable in the scope:

        $scope.options = {
            dataSource: {
                type: "json",
                transport: {
                    read: "app/data/myData.json"
                },
                pageSize: 10,
                schema  : {
                    data: "mySchema"
                }
            },
            sortable: true,
            pageable: true,
            resizable: true,
            columns:$scope.myHeaders
    ....
    ....

But the binding doesn't kick in, the headers are not updated.

Thanks!


回答1:


Assuming you're only loading the headers once and it's okay to hide the table until the headers load, throw an ng-if="myHeaders" onto the kendo-ui grid element, remove columns from $scope.options and use k-columns on the element instead.

So:

<div kendo-grid k-options="options"></div>

becomes:

<div kendo-grid k-options="options" k-columns="myHeaders" ng-if="myHeaders"></div>


来源:https://stackoverflow.com/questions/23659321/binding-kendo-ui-grid-columns-headers-to-the-scope-in-angularjs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!