javascript 如何在javascript中将列表设置为剑道网格数据源?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20684678/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to set list as kendo grid datasource in javascript?
提问by MustafaP
I have a modelview list and want to set this list as kendo grid datasource in a kendo window .
我有一个模型视图列表,想在剑道窗口中将此列表设置为剑道网格数据源。
Ajax
阿贾克斯
$.ajax({
url: '@Url.Action("KatildigiKurslar", "Tanim")',
type: 'POST',
dataType: "json",
data: { kursiyerId: kursiyerId},
success: function (result) {
var kurslar =result.kurslar;
//----------I've tried like this but not working ----------------//
var dataSource = new kendo.data.DataSource({
data:kurslar
});
$('#GridKatildigiKurslar').data("kendoGrid").setDataSource(kurslar);
$("#KatildigiKurslar").data("kendoWindow").open();
},
async: false
});
Kendo Window / Grid
剑道窗口/网格
@(Html.Kendo().Window()
.Name("KatildigiKurslar")
.Title("Kat?ld??? Kurslar")
.Draggable()
.Content(
@<text>
@(Html.Kendo().Grid<OnlineKursKayit.ViewModels.KursiyerSinifViewModel>()
.Name("GridKatildigiKurslar")
.Columns(columns =>
{
columns.Bound(p => p.KursEgitmenAdi).Width(100);
columns.Bound(p => p.KursDonemi).Width(200);
columns.Bound(p => p.BaslangicTarihi).Width(200);
})
.Pageable()
.AutoBind(false)
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(7)
)
)
</text>)
.Visible(false)
.Resizable()
.Actions(actions => actions.Minimize().Maximize().Close())
)
Model View
模型视图
public class KursiyerSinifViewModel
{
public string KursEgitmenAdi { get; set; }
public string KursDonemi{ get; set; }
public string BaslangicTarihi{ get; set; }
}
回答by Brett
You are passing in the wrong thing to the setDataSource()function. You should pass in the dataSource object you created.
您将错误的内容传递给setDataSource()函数。您应该传入您创建的 dataSource 对象。
var dataSource = new kendo.data.DataSource({
data: kurslar
});
$('#GridKatildigiKurslar').data('kendoGrid').setDataSource(dataSource); // not kurslar
An alternate way to load your data into the grid without having to create a new data source object would be to do this:
无需创建新数据源对象即可将数据加载到网格中的另一种方法是:
$('#GridKatildigiKurslar').data('kendoGrid').dataSource.data(kurslar);

