尝试从本地数据源在我的剑道UI网格上设置默认排序列。我读了很多,我应该写:
sort: { field: "price", dir: "desc" }
放到数据源上。我试过这个,它仍然不工作(见下面的例子底部)。
这是我的代码的全部,我哪里出错了?
$('#grid').kendoGrid({
dataSource: [
{
date: "Feb 13 2014",
price: 5,
},
{
date: "Feb 15 2014",
price: 7,
},
{
date: "Feb 12 2014",
price: 6,
}
],
height:500,
sortable: true,
pageable: false,
columns: [
{
field: "date",
title: "Date"
},
{
field: "price",
title: "Price",
}
],
sort: {field: "price", dir: "desc"}
});
您在错误的地方定义了sort
行。你把它作为网格的属性之一,但它(如你所说)是数据源的属性之一。
将其作为数据源属性的子属性:
$('#grid').kendoGrid({
dataSource: {
data: [{
date: "Feb 13 2014",
price: 5,
}, {
date: "Feb 15 2014",
price: 7,
}, {
date: "Feb 12 2014",
price: 6,
}],
sort: {
field: "price",
dir: "desc"
}
},
height: 500,
sortable: true,
pageable: false,
columns: [{
field: "date",
title: "Date"
}, {
field: "price",
title: "Price",
}],
});
如果它仍然不工作,我可以提供一个jsFiddle为您工作。
如果你正在使用Telerik MVC控件,最终呈现给剑道UI
.DataSource(dataSource => dataSource
.Ajax()
.Sort(sort => sort.Add("City").Ascending()) // <-- initial sort expression
.Read(read => read.Action("Index", "Home"))
)