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

[Solved] Paging not working in MVC grid

1 Answer 178 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Jeff
Top achievements
Rank 1
Jeff asked on 04 Oct 2011, 12:14 AM
Hello, I've been at this for hours. I have a grid with checkboxes that works fine for a smaller amount of records.
When I enable paging and click on a number (I have 20 records per page with 393 total records), I get a postback to the page that originally "drew" the grid, i.e. the page used to select the search/selection query in order to display the specified records for the grid.
The URL in the address bar shows: localhost:27961/Home/MemberInput?ResultsGrid-page=4

MemberInput is the method in the Home controller where the Model (List) is populated from.

Here's some relevant information:
- Model in .cshtml file is defined as:

@model

 

List<SWApp_MVC.Models.MemberInfo>
-Grid is defined (in short) as:

 

@{ Html.Telerik().Grid(Model).Name( 

"ResultsGrid").Columns(columns => {

columns.Template(

@<text><input name="checkedMembers" id="checkedMembers" type="checkbox"

 value="@item.MemberKey" title="checkedMembers" />  </text>)

.HeaderTemplate(@<text>

 <input type="checkbox" title="check all records" id="checkAllMembers" />  </text>).ClientTemplate( 

"<input type='checkbox' id='chkMessage' name='checkeMembers' value='<#= MemberKey #>' />")  

.Width(50).HeaderHtmlAttributes(new {style = "text-align:center"}) .HtmlAttributes( 

new {style = "text-align:center"});  

columns.Template( 

columns.Bound(o => o.EmpID).Width(100).Title("Emp ID");
...

 

}).Pageable().Render();

-------------------
Any assistance would be greatly appreciated.

UPDATE: Well, I've made a bit of progress. Added the following to bottom of my grid definition: 

.DataBinding(dataBinding => dataBinding.Ajax().Select("_Paging", "Home")) 

 

This will now call a specific method "_Paging" in my "Home" controller. In that method I have the line: 

return View("GridResults", new GridModel(listOfParticipants)); 
 

Paging "sort of" works now. I can use next, last, previous, first links. The numbers disappear (page numbers) when I go to next page. May create separate post for that.

1 Answer, 1 is accepted

Sort by
0
Jeff
Top achievements
Rank 1
answered on 04 Oct 2011, 09:31 PM
Finally! Got it working!!! Took loads of Google time. The link that helped me zero-in on the resolution came from here
In short, I had to make judicious use of ClientTemplate. I needed the ClientTemplate for EACH of my "custom" columns. I had a couple of columns that had image links in them. The images were not being displayed once I went to a different page.
Also, I put the following at the top of my SiteLayout.cshtml:
<script src="@Url.Content("~/Scripts/modernizr-1.7.min.js")" type="text/javascript"></script>
       @(Html.Telerik().StyleSheetRegistrar().DefaultGroup(group => group.Add("telerik.common.css").Add("telerik.sunset.css").Combined(true).Compress(true)))
    @(Html.Telerik().StyleSheetRegistrar().DefaultGroup(group => group.Add("telerik.examples.css").Add("telerik.common.css").Add("telerik.rtl.css").Combined(true).Compress(true)))
That enable a Telerik grid to show, complete with arrows and larger numbers. That helped address the look and feel of the paging I had.
Next, in order to get the image links to work on subsequent pages I added the following to my Template columns:
     columns.Template(
 @<text> <a href="@Url.Action("HideRowPerm", "Home", new {id = item.MemberKey, useMock = false.ToString()})" onclick="javascript:return ConfirmHiding();" ><img src="@Url.Content("~/Content/themes/base/images/hide.png")" alt="Hide Perm" style="border: none;" /></a>  </text>)  .HeaderTemplate(   @<text>   Hide Row <br />Perm       </text>    )  .ClientTemplate(@"<a href=""/Home/HideRowPerm/<#= MemberKey #>""><img src=""/Content/themes/base/images/Hide.png"")></a>") .Width(15)  .HeaderHtmlAttributes(new { style = "text-align:center" })

  .HtmlAttributes(new { style = "text-align:center" });

 

 

 

Note the "ClientTemplate line, that ensures that link is available during paging.  Wish there were an easier way. The link above talks about creating an extension method.
Tags
Grid
Asked by
Jeff
Top achievements
Rank 1
Answers by
Jeff
Top achievements
Rank 1
Share this question
or