如何在javascript中将列表设置为剑道网格数据源? [英] How to set list as kendo grid datasource in javascript?
本文介绍了如何在javascript中将列表设置为剑道网格数据源?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个模型视图列表,想将此列表设置为剑道窗口中的剑道网格数据源.
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
});
剑道窗口/网格
@(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())
)
模型视图
public class KursiyerSinifViewModel
{
public string KursEgitmenAdi { get; set; }
public string KursDonemi{ get; set; }
public string BaslangicTarihi{ get; set; }
}
推荐答案
您向 setDataSource()
函数传递了错误的信息.您应该传入您创建的 dataSource 对象.
You are passing in the wrong thing to the setDataSource()
function. You should pass in the dataSource object you created.
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);
这篇关于如何在javascript中将列表设置为剑道网格数据源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文