Tuesday, July 7, 2015

Kendo MVC Grid: to use server side page

View:
@(Html.Kendo().Grid()
    .Name("JournalViewerGrid")
    .Pageable()
    .DataSource(dataSource => dataSource
        .Ajax()
        .PageSize(20)     @default to 10@
        .ServerOperation(true)  @default to true@

        .Read(read => read.Action("GetJournals", "JournalEntryViewer"))
        .Sort(sort => sort.Add(model => model.JournalEntryId).Descending())
        .Model(model => model.Id(p => p.JournalEntryId))
        )
)


Controller action:

public ActionResult GetJournals([DataSourceRequest] DataSourceRequest request)
        {
            return Json(db.vwAllJournalEntries.Select(je => new JournalEntryViewerViewModel
            {
                JournalEntryId = je.JournalEntryId,
                LegalEntityId = je.LegalEntityId,
                ......
            }).ToDataSourceResult(request));
        }

No comments: