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

How to set up initial page number in MVC Razor?

3 Answers 478 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Gilmor
Top achievements
Rank 1
Gilmor asked on 01 Aug 2012, 10:24 AM

Hi

I need to set up initial page number for kendo grid on my MVC Razor form. In previous telerik.mvc grid component I could do somethink like that:

@Html.Telerik().Grid(Model).Name( ... ). 
        Columns( ... ).
        Pageable(o =>
                     {
                         o.Enabled(true);
                         o.PageSize(30);
                         o.PageTo(5);
                     }).
        EnableCustomBinding(true).
        DataBinding(...).
        Render();
        }

But in Kendo, Pageablebuilder doesn't contains any more PageSize and PageTo functions.

"PageSize" I can set with DataSource binding, but what with "PageTo". Where can I set it in Kendo?

3 Answers, 1 is accepted

Sort by
0
James Vassallo
Top achievements
Rank 2
answered on 25 Sep 2012, 07:08 AM
Hi, I need assistance with this as well please.

Is there a PageTo function for the Kendo server-side wrapper for Grid? Or is there an alternate way to specify the initial page?
0
Janusz
Top achievements
Rank 1
answered on 25 Sep 2012, 08:12 AM

You can specify current page in data source. In my case, with custom AJAX binding:

@{
    var pageNum = Model.PageNumber;      
    var pageSize = Model.PageSize;
    var requiredMinCount = pageNum*pageSize;
      
    Html.Kendo().Grid<...>()
        ...
        .DataSource(
            db => 
                db.Ajax()
                    .Read("GridDataBinding", "Correspondence")
                    .PageSize(@pageSize)
                    .Total(@requiredMinCount))        
        .Render();
}

One thing that you must keep in mind is to set the total number of rows to a value greater than or equal to "pageNumber * pageSize", because kendo checks it when loading pages and if it finds that there is not enough rows, then open grid on the first page.

I don't pass the actual amount of all rows on the RAZOR template, because I'm using AJAX binding, so I have to be calculated it in a controller action which returns data for the grid. It doesn't make sense to connect twice to a data source and double calculate the same value.

0
Nirav
Top achievements
Rank 1
answered on 02 Apr 2013, 01:36 PM
On first time page load, the Model is null.
I need assistance on this.
Tags
Grid
Asked by
Gilmor
Top achievements
Rank 1
Answers by
James Vassallo
Top achievements
Rank 2
Janusz
Top achievements
Rank 1
Nirav
Top achievements
Rank 1
Share this question
or