且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将kendo ui网格绑定到json文件,而不用在代码中生成网格

更新时间:2022-10-29 18:40:34

这终于为我工作:

 < div kendo-grid k -options = 选项 &GT;&LT; / DIV&GT; 


$ scope.options = {
dataSource:{
type:json,
transport:{
read:app /data/test.json

pageSize:10
},
sortable:true,
pageable:true,
列:[{
字段:firstName,
title:名字
},{
字段:lastName,
标题:姓氏

},{
字段:国家
}]
};


I'm trying to bind a kendo ui grid to a json file with no luck.

All the examples I found were when creating the grid in code. I need to do it declaratively.

Is it the same to put the dataSource separately in the scope as I did, or inside the "options"?

If I set the "myDataSrc" to a simple array in code, the binding works. But as a " kendo.data.DataSource" from a file, it does not.

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


        $scope.myDataSrc = new kendo.data.DataSource({
            transport: {
                read: {
                    url: "test.json",
                    dataType: "json"
                }
            }
        });

        $scope.options = {
            sortable: true,
            pageable: true,
            columns: [{
                field: "firstName",
                title: "First Name"
            },{
                field: "lastName",
                title: "Last Name"

            },{
                field: "country"
            },{
                field: "City"
            },{
                field: "Title"
            }]
        };


[
    { "firstName":"John" , "lastName":"Doe", "country": "country1" },
    { "firstName":"Anna" , "lastName":"Smith", "country": "country2" },
    { "firstName":"Peter" , "lastName":"Jones", "country": "country3" }
]

Thanks!

This finally worked for me:

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


        $scope.options = {
            dataSource: {
                type: "json",
                transport: {
                    read: "app/data/test.json"
                },
                pageSize: 10
            },
            sortable: true,
            pageable: true,
            columns: [{
                field: "firstName",
                title: "First Name"
            },{
                field: "lastName",
                title: "Last Name"

            },{
                field: "country"
            }]
        };