我已将此代码用作保存网格状态的模板: http://www.kendoui.com/code-library/web/grid/preserve-grid-state-in-a-cookie.aspx
只要我坚持除了分组之外的所有内容,这都有效。一旦我启用了持久化分组,我就会从Kendo javascript中收到此错误:“无法读取未定义的属性'长度'
这是使用HtmlHelper的网格:
@(Html.Kendo().Grid<VideoSummaryModel>()
.Name("VideosGrid")
.Columns(columns => {
columns.Bound(v => v.Topics).Title("Topic");
columns.Bound(v => v.Title)
columns.Bound(v => v.LastUpdated).Format("{0:MM/dd/yyyy}");
columns.Bound(v => v.InstructorName)
})
.Pageable()
.Sortable()
.Filterable()
.Groupable(grouping=>grouping.Enabled(!HasInstructorFilter))
.Events(evt => {
evt.DataBound("persistLibraryGrid");
})
.DataSource(ds => ds
.Ajax()
.PageSize(25)
.Read(read => read.Action("Index", "Videos", new { searchString = ViewBag.SearchString }))
))
以下是将状态保存在cookie中的代码:
//kendo grid
function persistGridSettings(grid, pageName) {
if (grid && grid.dataSource){
var dataSource = grid.dataSource;
group = dataSource.group();
var state = kendo.stringify({
page: dataSource.page(),
pageSize: dataSource.pageSize(),
sort: dataSource.sort(),
//There is a bug in the programmatic interaction with the grouping collection
group: dataSource.group(),
filter: dataSource.filter()
});
setCookie(getGridCookieName(pageName), state);
}
}
以下是将cookie加载回网格状态的代码:
function getGridSettings(grid, pageName) {
if (grid && grid.dataSource) {
var state = JSON.parse(getCookie(getGridCookieName(pageName)));
if (state) {
if (state.filter) {
parseFilterDates(state.filter, grid.dataSource.options.schema.model.fields);
}
grid.dataSource.query(state);
}
else {
grid.dataSource.read();
}
}
}
杰里米