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

[Solved] Grid Binding Issue When Last Page Reached

1 Answer 51 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.
Matthew Vermeulen
Top achievements
Rank 1
Matthew Vermeulen asked on 11 Dec 2009, 02:29 AM
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 });
        }






1 Answer, 1 is accepted

Sort by
0
Georgi Krustev
Telerik team
answered on 11 Dec 2009, 09:53 AM
Hello Matthew,

I tried to reproduce the depicted issue on our online demo, but no avail. Could you please verify that the correct Page and PageSize are send to the server and that the filter is the right one?

Best wishes,
Georgi Krustev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Grid
Asked by
Matthew Vermeulen
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Share this question
or