This question is locked. New answers and comments are not allowed.
Hi,
I am using custom binding with AJAX with the Grid control. Everything works fine until I reach the last page which contains only 3 items.
Then, if I try to view any other page I only get the first 3 rows for all fields that are created through data binding. Other fields (like the 'edit' field) display normally.
Any suggestions. Please see below for my code.
Regards,
Matt Vermeulen
=====
VIEW
=====
<%@ Control Language="C#" AutoEventWireup="true" Inherits="MvcContrib.FluentHtml.ModelViewUserControl<PatientSearchForm>" %>
<%@ Import Namespace="PathResultsPortal.Core.Domain"%>
<h2>Search Results</h2>
<%
Html.CreateGrid<Patient>("Patient", Model).Columns(column =>
{
column.Add(c => c.Id).Format
(Html.ActionLink("edit", "Edit", new { id = "{0}" }
, new { @class = "action-edit" }))
.Encoded(false).Filterable(false).Sortable(false).Title("");
column.Add(c => String.Format("{0}, {1}", c.Surname.ToUpper(), c.GivenName)).Title("Name");
column.Add(c => c.Sex == "M" ? "Male" : "Female").Title("Gender");
column.Add(c => c.HomePhoneNum).Title("Home Phone");
column.Add(c => c.DateOfBirth.ToString("dd/MM/yyyy")).Title("D.O.B");
}).Render();
%>
=========================================
THE HTML HELPER METHOD CALLED FROM VIEW
=========================================
public static GridBuilder<T> CreateGrid<T>(this HtmlHelper htmlHelper, string name,
string actionName, string controllerName, ISearchForm<T> model) where T:PersistentObject
{
return htmlHelper.Telerik().Grid(model.Results)
.Name(name)
.Ajax(ajax => ajax.Action(actionName, controllerName))
.Pageable(p => p.Enabled(true))
.Pageable(p => p.PageSize(model.FilterBase.ResultsPerPage))
.Pageable(p => p.Total((int)model.TotalResults))
.EnableCustomBinding(true)
.Sortable();
}
public static GridBuilder<T> CreateGrid<T>(this HtmlHelper htmlHelper,
string controllerName, ISearchForm<T> model) where T : PersistentObject
{
return CreateGrid<T>(htmlHelper, controllerName + "grid", "GridPageRequest", controllerName, model);
}
============
CONTROLLER
============
[GridAction(EnableCustomBinding = true)]
public virtual ActionResult GridPageRequest(GridCommand command)
{
SearchFilterBase filter = new PatientSearchFilter();
if (Request.Cookies.Get(m_patientSearchCookie) != null)
{
string searchFilter = Request.Cookies[m_patientSearchCookie].Value;
filter = JsonConvert.DeserializeObject<PatientSearchFilter>(searchFilter);
}
return base.GetSearchResultPage<Patient>(command, filter, m_patientRepository);
}
protected ActionResult GetSearchResultPage<T>(GridCommand command, SearchFilterBase filter, IRepository<T> repository) where T : PersistentObject
{
filter.FirstResult = ((command.Page - 1) * (command.PageSize));
IList<T> items = repository.GetAll(filter);
int totalresults = (int)repository.GetCount(filter);
return View(new GridModel<T>() { Data = items, Total = totalresults });
}
I am using custom binding with AJAX with the Grid control. Everything works fine until I reach the last page which contains only 3 items.
Then, if I try to view any other page I only get the first 3 rows for all fields that are created through data binding. Other fields (like the 'edit' field) display normally.
Any suggestions. Please see below for my code.
Regards,
Matt Vermeulen
=====
VIEW
=====
<%@ Control Language="C#" AutoEventWireup="true" Inherits="MvcContrib.FluentHtml.ModelViewUserControl<PatientSearchForm>" %>
<%@ Import Namespace="PathResultsPortal.Core.Domain"%>
<h2>Search Results</h2>
<%
Html.CreateGrid<Patient>("Patient", Model).Columns(column =>
{
column.Add(c => c.Id).Format
(Html.ActionLink("edit", "Edit", new { id = "{0}" }
, new { @class = "action-edit" }))
.Encoded(false).Filterable(false).Sortable(false).Title("");
column.Add(c => String.Format("{0}, {1}", c.Surname.ToUpper(), c.GivenName)).Title("Name");
column.Add(c => c.Sex == "M" ? "Male" : "Female").Title("Gender");
column.Add(c => c.HomePhoneNum).Title("Home Phone");
column.Add(c => c.DateOfBirth.ToString("dd/MM/yyyy")).Title("D.O.B");
}).Render();
%>
=========================================
THE HTML HELPER METHOD CALLED FROM VIEW
=========================================
public static GridBuilder<T> CreateGrid<T>(this HtmlHelper htmlHelper, string name,
string actionName, string controllerName, ISearchForm<T> model) where T:PersistentObject
{
return htmlHelper.Telerik().Grid(model.Results)
.Name(name)
.Ajax(ajax => ajax.Action(actionName, controllerName))
.Pageable(p => p.Enabled(true))
.Pageable(p => p.PageSize(model.FilterBase.ResultsPerPage))
.Pageable(p => p.Total((int)model.TotalResults))
.EnableCustomBinding(true)
.Sortable();
}
public static GridBuilder<T> CreateGrid<T>(this HtmlHelper htmlHelper,
string controllerName, ISearchForm<T> model) where T : PersistentObject
{
return CreateGrid<T>(htmlHelper, controllerName + "grid", "GridPageRequest", controllerName, model);
}
============
CONTROLLER
============
[GridAction(EnableCustomBinding = true)]
public virtual ActionResult GridPageRequest(GridCommand command)
{
SearchFilterBase filter = new PatientSearchFilter();
if (Request.Cookies.Get(m_patientSearchCookie) != null)
{
string searchFilter = Request.Cookies[m_patientSearchCookie].Value;
filter = JsonConvert.DeserializeObject<PatientSearchFilter>(searchFilter);
}
return base.GetSearchResultPage<Patient>(command, filter, m_patientRepository);
}
protected ActionResult GetSearchResultPage<T>(GridCommand command, SearchFilterBase filter, IRepository<T> repository) where T : PersistentObject
{
filter.FirstResult = ((command.Page - 1) * (command.PageSize));
IList<T> items = repository.GetAll(filter);
int totalresults = (int)repository.GetCount(filter);
return View(new GridModel<T>() { Data = items, Total = totalresults });
}