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

Set initial Grid page so it displays page other than first page

1 Answer 1017 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mike
Top achievements
Rank 1
Mike asked on 01 Aug 2013, 01:24 AM
I have built an MVC Kendo Helper Grid that needs to display something other than the first page from the DataSource. I set the AutoBind to false, and ServerOperation to true. 

I then have some javascript code which calls the page() function with the number 2, however during this call the controller still receives a  1. What am I doing wrong, or is there another way to set the initial page? Here is the code:

                @(Html.Kendo().Grid<SF_SatAppsMVC4.Models.MD_GetUpcomingMTCEventsResult>().Name("gridUpcomingMTC")
                    .HtmlAttributes(new { @class = "clickableGrid" })
                    .AutoBind(false)
                    .DataSource(datasource => datasource
                    .Ajax()
                    .ServerOperation(true)
                    .PageSize(5)
                    .Read(read => read.Action("GetUpcomingEvents", "ControllerCenter", new { locationID = @ViewBag.locationID })))
                    .Pageable()
                    .Columns(cols =>
                    {
                        cols.Bound(p => p.eventDate).Format("{0:dd-MMM}").Title("Date");
                        cols.Bound(p => p.Presenter);
                     }))

    
<script>
    $(function () {
        debugger;
        $('#gridUpcomingMTC').data("kendoGrid").dataSource.page(2);
    })
</script>

1 Answer, 1 is accepted

Sort by
0
Dimiter Madjarov
Telerik team
answered on 02 Aug 2013, 11:25 AM
Hello Mike,


The reason for the issue is that on document ready, the grid is not yet bound to the data and basically it has 0 pages. So in the current implementation the page() method is called on an empty grid. As a workaround you could use the one method to bind a handler to the dataBound event, which will be executed only once and perform the paging over there.
E.g.
$(function () {
    var grid = $("#grid").data("kendoGrid");
    grid.one("dataBound", function () {
        this.dataSource.page(2);
    });
});

I wish you a great day!
 
Regards,
Dimiter Madjarov
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
Mike
Top achievements
Rank 1
Answers by
Dimiter Madjarov
Telerik team
Share this question
or