0

我已将此代码用作保留网格状态的模板: http ://www.kendoui.c​​om/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();
        }
    }
}

杰里米

4

0 回答 0