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

Kendo Grid Remote Virtual Data With Paging Support

1 Answer 81 Views
Grid
This is a migrated thread and some comments may be shown as answers.
jwize
Top achievements
Rank 1
jwize asked on 12 Sep 2013, 02:32 AM
It doesn't seem to work for me
It is supposed to but I haven't found complete documentation on how to do this. For example I was able to set Virtual to true with the following code(note I am using MVC extensions).
.Scrollable(s => s.Virtual(true).Height(532))
The server code
public ActionResult IndexEmployeesGridData([DataSourceRequest] DataSourceRequest request)
{  
    var model = _employeeService.GetEmployeesDataViewModel(request.Page, request.PageSize).Where(e => e.IsActive);
    return Json(model.ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
}


Code works for the first page only.

The grid fills up with the first page of data but nothing else. Since the grid has no idea how many rows are in the database it just forgets about any more records. I don't know how to complete the last part to get the dynamic virtual paging  to work properly. Any help would be greatly appreciated. 

Thanks

1 hour ago (Link to this post)

It doesn't seem to work for me
It is supposed to but I haven't found complete documentation on how to do this. For example I was able to set virtualization to true with the following code(note I am using MVC extensions).
.Scrollable(s => s.Virtual(true).Height(532))
This of course doesn't work well for large datasets because you have to have some sort of paging set up on the server. There is documentation saying that you should add the parameters page, pageSize, take, and skip etc.. in order for this to work. I did this but then I get an error. 

The server code
public ActionResult IndexEmployeesGridData([DataSourceRequest] DataSourceRequest request, Int32 page, Int32 pageSize)
{  
    var model = _employeeService.GetEmployeesDataViewModel(page, pageSize).Where(e => e.IsActive);
    return Json(model.ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
}
The erorr message
Server Error in '/' Application.The parameters dictionary contains a null entry for parameter 'page' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult IndexEmployeesGridData(Kendo.Mvc.UI.DataSourceRequest, Int32, Int32)' in 'SafetyPlus.Controllers.EmployeeController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter.
Parameter name: parameters

Using the Data property I was able to get data to the server. 
.DataSource(datasource => datasource
    .Ajax()
    .PageSize(20)
    .Read(read => read.Action("IndexEmployeesGridData", "Employee").Data("sendStatus"))))
And the script that gets the parameters to take. 
<script type="text/javascript">
 
    function sendStatus(options)
        return {
            page: options.page,
            pageSize: options.pageSize
        };
    }
</script>
Help needed.
The grid fills up with the first page of data but nothing else. Since the grid has no idea how many rows are in the database it just forgets about any more records. I don't know how to complete the last part to get the paging to work properly. Any help would be greatly appreciated. 

Thanks

1 Answer, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 13 Sep 2013, 02:10 PM
Hello Jaime,

Since it seems that you are performing the paging with custom code you should initialize a new DataSourceResult with the data and the total number of records instead of using the ToDataSourceResult method:

public ActionResult IndexEmployeesGridData([DataSourceRequest] DataSourceRequest request)
    var data = GetAllData().Where(e => e.IsActive);
    var total = data.Count();
    var result = new DataSourceResult
            {
                 Data = GetPagedData(data, request.Page, request.PageSize),
                 Total = total
            };
    return Json(result, JsonRequestBehavior.AllowGet);
}
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
jwize
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Share this question
or