且构网

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

如何将json数据绑定到kendo网格

更新时间:2022-10-21 14:32:04

(function(){

//调用kendogrid函数


(#grid)。kendoGrid({//使用kendo ui javascript api获取列名

列:[{title:名字,字段:firstname,模板:

#= firstname#

},//列标题的标题,设置名字的模板

{标题:姓氏,字段:姓氏,模板:

#= lastname #

},

{标题:图片,字段:图片,模板:< img src ='#=图片#'height ='100'width = '150'/>},//指定图片列的模板

{title:Email,字段:email,模板:#= email#}

],

dataSource:{

//数据:人,//不使用本地javascript数组作为上述数据但是来自json

运输:

{

阅读:

{

url:data / people.json

}

},

架构:

{

数据:数据,

总计:计数

},

pageSize: 3

},

身高:400,

可滚动:true,

pageable:true,

sortable:true,

groupable:true

});





});

< / script>

< / body>

< / html>





//内部数据/ people.json



[

{

firstname:Todd,

姓氏:Anglin,

picture:images / todd.jpg,

email:todd.anglin@gmail.com
},

{

firstname:Ronn,

lastname:Jobs,

picture:images / ronn.jpg,

email:ronn.jobs@hotmail.com

} ,

{

firstname:Malisa,

lastname:Hanks,

picture:images / malisa.jpg,

email:mali.hanks@yahoo.com

},

{

firstname:Torey,

lastname:Wilson,

picture:images / torey .jpg,

email:torey@gmail.com

}

]



我收到404错误,无法加载json文件。



谢谢



我尝试过:



(#grid)。kendoGrid({//使用kendo ui javascript api获取列名

列:[{title:First Name,字段:firstname,模板:

#= firstname#

},//列标题的标题,设置名字的模板

{title:姓氏,字段:姓氏,模板:

#=姓氏#

},

{标题:图片,字段:图片,模板:&lt ; img src ='#= picture#'height ='100'width ='150'/>},//指定图片列的模板

{title:Email,字段: 电子邮件,模板:#=电子邮件#}

],

dataSource:{

/ / data:people,//不使用本地javascript数组作为数据,但是来自json

transport:

{

读取:

{

// url:data / people.json

url:people.json

}

},

架构:

{

数据:数据,

总计: 数

},

pageSize:3

},

身高:400,

可滚动:true,

pageable:true,

sortable:true,

groupable:true

});


Hi All,

I have this code for binding kendo json data to kendo grid but its not working. Please help me out. Here is the code that I was working with.

//inside HtmlPage1.html

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled</title>

<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="http://kendo.cdn.telerik.com/2016.1.226/js/angular.min.js"></script>
<script src="http://kendo.cdn.telerik.com/2016.1.226/js/jszip.min.js"></script>
<script src="http://kendo.cdn.telerik.com/2016.1.226/js/kendo.all.min.js"></script>
</head>
<body>




<script>
$(function () {
//calling the kendogrid function
$("#grid").kendoGrid({ //using kendo ui javascript api to get column names
columns: [{ title: "First Name", field: "firstname", template: "

#= firstname #

" },//title for column header, setting template for firstname
{ title: "Last Name", field: "lastname", template: "

#= lastname #

" },
{ title: "Picture", field: "picture", template: "<img src='#=picture #' height='100' width='150'/>" },//specifying template for picture column
{ title: "Email", field: "email", template: "#=email#" }
],
dataSource: {
//data: people, //not using the local javascript array as data as above but from json
transport:
{
read:
{
url: "data/people.json"
}
},
schema:
{
data: "data",
total: "count"
},
pageSize: 3
},
height: 400,
scrollable: true,
pageable: true,
sortable: true,
groupable: true
});


});
</script>
</body>
</html>


//inside data/people.json

[
{
"firstname": "Todd",
"lastname": "Anglin",
"picture": "images/todd.jpg",
"email": "todd.anglin@gmail.com"
},
{
"firstname": "Ronn",
"lastname": "Jobs",
"picture": "images/ronn.jpg",
"email": "ronn.jobs@hotmail.com"
},
{
"firstname": "Malisa",
"lastname": "Hanks",
"picture": "images/malisa.jpg",
"email": "mali.hanks@yahoo.com"
},
{
"firstname": "Torey",
"lastname": "Wilson",
"picture": "images/torey.jpg",
"email": "torey@gmail.com"
}
]

I get 404 error that json file could not be loaded.

Thanks

What I have tried:

$("#grid").kendoGrid({ //using kendo ui javascript api to get column names
columns: [{ title: "First Name", field: "firstname", template: "

#= firstname #

" },//title for column header, setting template for firstname
{ title: "Last Name", field: "lastname", template: "

#= lastname #

" },
{ title: "Picture", field: "picture", template: "<img src='#=picture #' height='100' width='150'/>" },//specifying template for picture column
{ title: "Email", field: "email", template: "#=email#" }
],
dataSource: {
//data: people, //not using the local javascript array as data as above but from json
transport:
{
read:
{
//url: "data/people.json"
url:"people.json"
}
},
schema:
{
data: "data",
total: "count"
},
pageSize: 3
},
height: 400,
scrollable: true,
pageable: true,
sortable: true,
groupable: true
});

(function () {
//calling the kendogrid function


("#grid").kendoGrid({ //using kendo ui javascript api to get column names
columns: [{ title: "First Name", field: "firstname", template: "
#= firstname #

" },//title for column header, setting template for firstname
{ title: "Last Name", field: "lastname", template: "

#= lastname #

" },
{ title: "Picture", field: "picture", template: "<img src='#=picture #' height='100' width='150'/>" },//specifying template for picture column
{ title: "Email", field: "email", template: "#=email#" }
],
dataSource: {
//data: people, //not using the local javascript array as data as above but from json
transport:
{
read:
{
url: "data/people.json"
}
},
schema:
{
data: "data",
total: "count"
},
pageSize: 3
},
height: 400,
scrollable: true,
pageable: true,
sortable: true,
groupable: true
});


});
</script>
</body>
</html>


//inside data/people.json

[
{
"firstname": "Todd",
"lastname": "Anglin",
"picture": "images/todd.jpg",
"email": "todd.anglin@gmail.com"
},
{
"firstname": "Ronn",
"lastname": "Jobs",
"picture": "images/ronn.jpg",
"email": "ronn.jobs@hotmail.com"
},
{
"firstname": "Malisa",
"lastname": "Hanks",
"picture": "images/malisa.jpg",
"email": "mali.hanks@yahoo.com"
},
{
"firstname": "Torey",
"lastname": "Wilson",
"picture": "images/torey.jpg",
"email": "torey@gmail.com"
}
]

I get 404 error that json file could not be loaded.

Thanks

What I have tried:


("#grid").kendoGrid({ //using kendo ui javascript api to get column names
columns: [{ title: "First Name", field: "firstname", template: "
#= firstname #

" },//title for column header, setting template for firstname
{ title: "Last Name", field: "lastname", template: "

#= lastname #

" },
{ title: "Picture", field: "picture", template: "<img src='#=picture #' height='100' width='150'/>" },//specifying template for picture column
{ title: "Email", field: "email", template: "#=email#" }
],
dataSource: {
//data: people, //not using the local javascript array as data as above but from json
transport:
{
read:
{
//url: "data/people.json"
url:"people.json"
}
},
schema:
{
data: "data",
total: "count"
},
pageSize: 3
},
height: 400,
scrollable: true,
pageable: true,
sortable: true,
groupable: true
});