This is a migrated thread and some comments may be shown as answers.

MVC Grid Ajax paging not working

2 Answers 495 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Robert
Top achievements
Rank 1
Robert asked on 27 Aug 2013, 03:41 PM
I have a generic partial view that I want to use for all of my Grids.  The Model for the partial view it a Report object.  The Report object has a DataTable property that contains the Grid's data source.  The Report is also handling its own pages, page size, filtering, sorting, and grouping.  The Ajax call is returning with the correct total number of records and I know that the Report.Query.PagedResults has the correct data. However, when the DataTable is passed to the extension "ToDataSourceResult()" the Data comes back without the data provided in the PagedResults.  It's just an empty dictionary.  This causes the grid to change pages but the data is missing, only the first page ever has data.  Can you provide me with some guidance on what I might be missing?

_GridPartialView
@model GridReport
@using System.Data;
@using MVCReportingConcept.Reports;
<div id="report" class="chart-wrapper">
    @(Html.Kendo().Grid(Model.QueryResults)
        .Name(Model.Name)
        .EnableCustomBinding(true)
        .Columns(columns =>
        {
            foreach (DataColumn col in Model.QueryResults.Columns)
            {
                columns.Bound(col.ColumnName);
            }
        })
        .Pageable()
        .Sortable()
        .Scrollable()
        .Filterable()
        .DataSource(dataSource => dataSource
            .Ajax()
            .Total(Model.Query.TotalRecordCount)
            .Read(read => read.Action("ReadGrid", "Home", new { reportId = Model.ReportId }))
            .PageSize(Model.PageSize)
        )
    )
</div>
Controller Ajax Action (the comments are other failed attempts to get it to work)
public ActionResult ReadGrid([DataSourceRequest] DataSourceRequest request, int reportId)
{
    GridReport report = (GridReport)ReportBuilder.BuildReport(reportId);
    report.Refresh(request.Page, request.PageSize);
 
    DataSourceResult ds = report.Query.PagedResults.ToDataSourceResult(request);
    //ds = report.QueryResults.ToEnumerable().ToQueryable().ToDataSourceResult(request);
    //ds.Data = report.DataSourceResult.Data;
    ds.Total = report.Query.TotalRecordCount;
 
    return Json(ds);
}

2 Answers, 1 is accepted

Sort by
0
Robert
Top achievements
Rank 1
answered on 29 Aug 2013, 12:49 PM
Has any one been able to look at this issue?  When I pass my populated DataTable to the ToDataSourceResults extension method the returned results don't have anything in the Data property.
0
Daniel
Telerik team
answered on 29 Aug 2013, 04:14 PM
Hello Robert,

If the paging is performed with custom code then you should use an empty DataSourceRequest as parameter:

DataSourceResult ds = report.Query.PagedResults.ToDataSourceResult(new DataSourceRequest());
The ToDataSourceResult method will return an empty dictionary because it will query a page that does not exist in the already paged data.

Regards,
Daniel
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Grid
Asked by
Robert
Top achievements
Rank 1
Answers by
Robert
Top achievements
Rank 1
Daniel
Telerik team
Share this question
or