- Home
- Forum
- ASP.NET MVC
- How to restrict the number of rows in a grid page?
How to restrict the number of rows in a grid page?
I have a grid where the rows can be rather high, so I'd like to limit the number of rows. I tried adding ".PageSettings(a => a.PageSize(5))", but then the grid only says it has one page, even though there are 6 items in the dataset. Is this the right property to use in this case?
SIGN IN To post a reply.
1 Reply
JK
Jayaprakash Kamaraj
Syncfusion Team
December 5, 2016 11:57 AM UTC
Hi Brain,
Thank you for contacting Syncfusion Support.
Yes, you have used correct property of Grid to restrict the number of rows in a grid page. We have created a sample with PageSize as 5 in PageSettings. But we were unable to reproduce the issue at our end. Please refer to the below code example and screenshot.
| @(Html.EJ().Grid<SyncfusionMvcApplication29.OrdersView>("FlatGrid") .Datasource(ds => ds.URL("/Grid/DataSource").Adaptor("UrlAdaptor")) .AllowPaging() /*Paging Enabled*/ .PageSettings(a => a.PageSize(5)) .Columns(col => { col.Field("OrderID").HeaderText("Order ID").IsPrimaryKey(true).TextAlign(TextAlign.Right).Width(75).Add(); .. })) |
We suspect that you are using UrlAdaptor in Grid. So, we need to handle paging in server-side and also need to calculate data Count before the PerfromSkip() and PerformTake() operations. Please refer to the below code example, knowledge base document and sample.
https://www.syncfusion.com/kb/4300/server-side-api-for-datamanager-operations
| @(Html.EJ().Grid<SyncfusionMvcApplication29.OrdersView>("FlatGrid") .Datasource(ds => ds.URL("/Grid/DataSource").Adaptor("UrlAdaptor")) .AllowPaging() /*Paging Enabled*/ .PageSettings(a => a.PageSize(5)) .Columns(col => { col.Field("OrderID").HeaderText("Order ID").IsPrimaryKey(true).TextAlign(TextAlign.Right).Width(75).Add(); col.Field("CustomerID").HeaderText("Customer ID").Width(80).Add(); col.Field("EmployeeID").HeaderText("Employee ID").TextAlign(TextAlign.Right).Width(75).Add(); col.Field("Freight").HeaderText("Freight").TextAlign(TextAlign.Right).Width(75).Format("{0:C}").Add(); })) GridController.cs public ActionResult DataSource(Syncfusion.JavaScript.DataManager dm) { IEnumerable Data = new NorthwindDataContext().OrdersViews.ToList(); Syncfusion.JavaScript.DataSources.DataOperations operation = new Syncfusion.JavaScript.DataSources.DataOperations(); int count = Data.AsQueryable().Count(); if (dm.Skip != 0) { Data = operation.PerformSkip(Data, dm.Skip); } if (dm.Take != 0) { Data = operation.PerformTake(Data, dm.Take); } return Json(new { result = Data, count = count }, JsonRequestBehavior.AllowGet); } |
If you still facing the problem, Please share the video or screenshot to show the issue.
Regards,
Jayaprakash K.
SIGN IN To post a reply.
- 1 Reply
- 2 Participants
-
RB R Brian Lindahl
- Dec 3, 2016 12:15 AM UTC
- Dec 5, 2016 11:57 AM UTC