Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET MVC 3 WebGrid paging issue

My data access layer returns collection with rows for single page and total number of rows.

Unfortunately WebGrid component does not allow to specify total number of rows or total number of pages (these properties are read-only).

Has anyone had to deal with this issue before?

like image 433
Daniil Harik Avatar asked Nov 15 '10 14:11

Daniil Harik


3 Answers

You can use the Bind method on the WebGrid to tell the grid to use server side paging.

grdv.Bind(myData, rowCount=10000, autoSortAndPage=False)

Setting autoSortAndPage to false tells the grid that myData is just a segment of the data. It will show all rows of this data regardless of your page size setting. Pager will be built using the rowCount you pass in and not the number of records in myData.

like image 82
Einar Arne Avatar answered Nov 18 '22 23:11

Einar Arne


EDIT: I see what your question is now. Check out this article for not using the WebGrid.

Paging with WebGrid

From this page, it looks like you can specify rows per page.

var grid = new WebGrid(source, rowsPerPage : 25);

And this page (look at line 9 from the first code block).

like image 25
Martin Avatar answered Nov 19 '22 01:11

Martin


rowsPerPage is only settable through the constructor. This was done to keep the helper simple and avoid handling complex states. Total rows comes from the data source.

like image 2
chenriks Avatar answered Nov 19 '22 00:11

chenriks