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

[Solved] Paging and Total Records

3 Answers 200 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
Top achievements
Rank 1
Matthew asked on 19 Nov 2009, 08:32 PM
The pager doesn't seem to be working correctly. I am setting the Total number of records but the pager is rendering as if there were only 1 page of results when there should be many.

I am executing a linq query using Skip and Take to only grab the requested page of results.

Here is my controller

public ActionResult AdvancedSearch(DisputeSearch search) 
    var results = disputeService.Search(search).Skip(idx).Take(PageSize).OrderBy(d => d.DisputeID).ToList(); 
    DisputeSearchViewModel dsrvm = new DisputeSearchViewModel() 
    { 
        Disputes = results, 
        TotalRecords = disputeService.Search(search).Count() 
    }; 
    return View("SearchResults", dsrvm); 
 

Here is my view code

        <% Html.Telerik().Grid<DisputeSearch>(Model.Disputes) 
               .Name("disputesgrid").PrefixUrlParameters(false) 
             .AssetKey("gridAssetGroup") 
             .Columns(columns => 
             { 
               columns.Add(d => d.DisputeID).Width(50); 
               columns.Add(d => d.TerminalID).Width(50); 
               columns.Add(d => d.ResponseDueDate).Width(50); 
               columns.Add(d => d.CreateDate).Width(50); 
               columns.Add(d => 
               { 
               %> 
                 <%= Html.ActionLink("Details", "Details", new { id = d.DisputeID })%> 
               <
               }).Title(" ").Width(50).HtmlAttributes(new { align = "center" }); 
             }) 
             .Sortable(sort => sort.SortMode(GridSortMode.SingleColumn)) 
             .Pageable(paging => paging.PageSize(20).Style(GridPagerStyles.NextPreviousAndNumeric).Total(Model.TotalRecords)) 
             .Render(); 
        %> 
 

3 Answers, 1 is accepted

Sort by
0
Kazi Manzur Rashid
Telerik team
answered on 20 Nov 2009, 09:00 AM
Hi Matthew,

I think you are doing custom data binding instead of using our built-in data engine, in that case you have
to set the EnableCustomBinding to true, in this way our data engine will not come into the action. For a fully functional demo, pls check the following example:

http://demos.telerik.com/aspnet-mvc/grid/custombinding

All the best,
Kazi Manzur Rashid
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.
0
Josh
Top achievements
Rank 1
answered on 07 May 2010, 09:14 PM
I am attempting to use custom binding with no success. No matter what is entered into Total the grid only shows the total equal to the size of the IEnumerable stored in viewModel.DataSource

Here is my controller action:
[MvcCore.Attributes.RequireRequestValue(new[] { "PartNumber" })] 
        [AcceptVerbs(HttpVerbs.Post)] 
        [UrlRoute(Path = "LCM/Catalog")] 
        public virtual ActionResult Catalog(SimpleSearchFilter simpleSearchModel) 
        { 
            Check.Argument.IsNotNull(simpleSearchModel, "simpleSearchModel"); 
 
            CatalogGridModel<LcmGridPartSearchResult> viewModel = GetModel(); 
             
            var result = SimpleSearch(simpleSearchModel.PartNumber, CurrentUser.PersonaId, 
                ExcludeProprietary, SkipRowCount, viewModel.PageSize); 
 
            viewModel.DataSource = result.PageItems; 
            viewModel.SimpleSearchFilter = simpleSearchModel; 
            viewModel.Total = result.TotalCount; 
            viewModel.SearchType = CatalogGridModel<LcmGridPartSearchResult>.SearchTypes.SimpleSearch; 
 
            return View(viewModel); 
        } 

And here is my view code:

Html.Telerik().Grid<TradeWings.DAL.ReEntities.LcmGridPartSearchResult>(Model.DataSource) 
                        .Name("Grid"
                        .EnableCustomBinding(true
                        .Columns(columns => 
                        { 
                            columns.Add(o => o.Part_ID).Title("PartID").Width(105); 
                            columns.Add(o => o.PartNumber).Title("Product/PartNumber").Width(195); 
                            columns.Add(o => o.PartRevision).Title("Revision").Width(115); 
                            columns.Add(o => o.PartDesc).Title("Product Description").Width(180); 
                            columns.Add(o => o.HazMatHandlingRequired).Title("HazMatHandlingRequired").Width(250); 
                            columns.Add(o => o.CombinedCertifiedCode).Title("CombinedCertifiedCode").Width(250); 
                            columns.Add(o => o.CombinedCertifiedCodeName).Title("CurrentStatus").Width(200); 
                            columns.Add(o => o.Manufacturer).Title("Manufacturer").Width(200); 
                            columns.Add(o => o.ProductFamily).Title("ProductFamily").Width(200); 
                            columns.Add(o => o.ProductName).Title("ProductName").Width(200); 
                            columns.Add(o => o.HazMatProcess).Title("HazMatProcess").Width(200); 
                            columns.Add(o => o.CountryOfOrigin).Title("CountryOfOrigin").Width(200); 
 
                            columns.Add(o => o.NetWeight).Title("NetWeight").Width(120); 
                            columns.Add(o => o.Length).Title("Length").Width(120); 
                            columns.Add(o => o.Width).Title("Width").Width(120); 
                            columns.Add(o => o.Height).Title("Height").Width(120); 
 
                            columns.Add(o => o.LifeCycleStatus).Title("LifeCycleStatus").Width(200); 
                            columns.Add(o => o.Technology).Title("Technology").Width(200); 
                            columns.Add(o => o.Criticality).Title("Criticality").Width(200); 
                            columns.Add(o => o.SparePartCode).Title("SparePartCode").Width(200); 
                            columns.Add(o => o.USEccnCode).Title("USEccnCode").Width(200); 
                            columns.Add(o => o.EuEccnCode).Title("EuEccnCode").Width(200); 
                            columns.Add(o => o.UsHstCode).Title("UsHstCode").Width(200); 
                            columns.Add(o => o.EuHstCcode).Title("EuHstCcode").Width(200); 
                            columns.Add(o => o.CustomsValue).Title("CustomsValue").Width(200); 
                            columns.Add(o => o.RoHsLevel).Title("RoHsLevel").Width(200); 
                            columns.Add(o => o.AltProductNumber).Title("AltProductNumber").Width(200); 
                            columns.Add(o => o.CLEI).Title("CLEI").Width(100); 
 
                            columns.Add(o => o.PackagingMaterial).Title("PackagingMaterial").Width(200); 
                            columns.Add(o => o.HardwareCompatibility).Title("HardwareCompatibility").Width(200); 
                            columns.Add(o => o.FirmwareCompatibility).Title("FirmwareCompatibility").Width(200); 
                            columns.Add(o => o.SoftwareCompatibility).Title("SoftwareCompatibility").Width(200); 
 
                            columns.Add(o => o.IntroductionDate).Title("IntroductionDate").Width(200); 
                            columns.Add(o => o.LastTimeBuyDate).Title("LastTimeBuyDate").Width(200); 
                            columns.Add(o => o.EndOfSupportDate).Title("EndOfSupportDate").Width(200); 
                            columns.Add(o => o.EndOfLifeDate).Title("EndOfLifeDate").Width(200); 
 
                            columns.Add(o => o.MTBFcalculated).Title("MTBFcalculated").Width(200); 
                            columns.Add(o => o.MTBFactual).Title("MTBFactual").Width(200); 
                        }) 
                        .CellAction(cell => 
                        { 
                            if (Model.IsEmptyGrid && isFirstColumn) 
                            { 
                                isFirstColumn = false
 
                                cell.HtmlAttributes["colspan"] = cell.DataItem.GetType().GetProperties().Length; 
                                cell.HtmlAttributes["class"] = "recordsNotFoundGridMessage"
                                cell.Text = "There are no items to display."
                            } 
 
                            if (string.Compare(cell.Text, "null"true) == 0) 
                            { 
                                cell.Text = string.Empty; 
                            } 
                        }) 
                        .ClientEvents(events => 
                        { 
                            events.OnRowDataBound("OnRowDataBound"); 
                        }) 
                        .Ajax(ajax => ajax.Enabled(!Model.IsEmptyGrid) 
                            .Action(MVC.LCMCatalog.CatalogAjax(), 
                                Model.SearchType == CatalogGridModel<LcmGridPartSearchResult>.SearchTypes.AdvancedSearch 
                                ? (object)Model.AdvancedSearchFilter 
                                : (object)Model.SimpleSearchFilter 
                            ) 
                        ) 
                        .EnableCustomBinding(false
                        .Sortable(sort => sort.Enabled(!Model.IsEmptyGrid)) 
                        .Scrollable(scroll => scroll.Enabled(true).Height(320)) 
                        .Filterable(filtering => filtering.Enabled(!Model.IsEmptyGrid)) 
                        .Pageable(page => page 
                            .Enabled(!Model.IsEmptyGrid) 
                            .PageSize(Model.PageSize) 
                            .Total(Model.Total) 
                        ) 
                        .Render(); 

Any assistance would be appreciated.

Thanks,

Josh


0
Atanas Korchev
Telerik team
answered on 10 May 2010, 08:09 AM
Hi Josh,

Your grid is not configured for custom binding. You have both EnableCustomBinding(true) and then EnableCustomBinding(false).

All the best,
Atanas Korchev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
Grid
Asked by
Matthew
Top achievements
Rank 1
Answers by
Kazi Manzur Rashid
Telerik team
Josh
Top achievements
Rank 1
Atanas Korchev
Telerik team
Share this question
or