我想用以下参考学习Kendo网格。用数据源绑定Kendo网格不显示数据
- Grid/Binding to local data
- How to use SetDataSource Method of the Kendo UI Grid
- How-To: Use the DataSource
- How-To: Bind the Grid to Remote Data
我有一个名为“localDataSource”的数据源。网格需要显示来自这个源的数据。我尝试在kendoGrid定义中定义dataSource: localDataSource
。然后我试着明确地设置了数据源grid.setDataSource(localDataSource);
尽管没有javascript错误,但这两种方法都没有渲染数据。这里缺少什么?
CODE
<head>
<title>Grid with DataSource</title>
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="http://cdn.kendostatic.com/2013.2.716/js/kendo.all.min.js"></script>
<style type="text/css">
table, th, td
{
border: 1px solid black;
}
</style>
</head>
<body>
<div id="example" class="k-content">
<div id="grid">
AAAA
</div>
<script>
$(document).ready(function() {
var products = [
{ title: "Nylon", year: 1977 },
{ title: "Fabric Material", year: 1980 },
{ title: "Yards UOM", year: 1983 }
];
var localDataSource = new kendo.data.DataSource({ data: products });
//console.log(localDataSource);
$("#grid").kendoGrid({
dataSource: localDataSource,
height: 430,
columns: [
{ field: "Title", title: "Title", format: "{0:c}", width: "130px" },
{ field: "Year", title: "Year", width: "130px" }
]
});
var grid = $('#grid').data("kendoGrid");
grid.setDataSource(localDataSource);
});
</script>
</div>
</body>