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

[Solved] Paging not working with sorting

3 Answers 148 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.
Sid
Top achievements
Rank 1
Sid asked on 20 Jun 2012, 09:46 PM
I've got a problem with a grid that will not display the correct number of records when the grid is sorted.

Here's the View code:
@(Html.Telerik().Grid(Model)
   .Name("grdSearch")
   .Columns(columns =>
                {
                    columns.Bound(c => c.serial_num)
                        .Title("Serial#");
                    columns.Bound(c => c.cust_cont_desc)
                        .Title("Description");
                    columns.Bound(c => c.rcpt_date).Format("{0:MM/dd/yyyy}")
                        .Title("Recv'd");
                    columns.Bound(c => c.status)
                        .Title("Stat");
                   columns.Command(commands => commands
                        .Custom("Use")
                        .Text("Use")
                        .DataRouteValues(route => route.Add(c => c.id).RouteKey("id"))
                        .Action("Use","CustContainer"))
                        .Width(80);                
                })
    .Sortable(sorting => sorting.OrderBy(sortOrder => sortOrder.Add(c => c.rcpt_date)))
    .Pageable(page => page.PageSize(5))
    )

So I don't see anything out of the ordinary, pretty basic grid.

The results view shows the same 8 records, but when the grid is sorted(asc or desc) it only displays 2 on the last page, so 7 records total.  ?????

Any help would be appreciated.

Thanks,
-Sid.

3 Answers, 1 is accepted

Sort by
0
Sid
Top achievements
Rank 1
answered on 21 Jun 2012, 02:13 PM
Here's another example:

View:
@model IEnumerable<JDContainers.Models.CustContainersLog>
@using Telerik.Web.Mvc.UI
 
@{
    ViewBag.Title = "Log";
    Layout = "~/Views/Shared/_Layout2.cshtml";
}
 
<h2>Container Tracking - Log</h2>
 
@(Html.Telerik().Grid(Model)
    .Name("grdLog")
    .Columns(columns =>
                 {
                     columns.Bound(l => l.emp_num)
                         .Title("Employee");
                     columns.Bound(l => l.LogDateTime)
                         .Title("Date");
                     columns.Bound(l => l.ActionType)
                         .Title("Action");
                     columns.Bound(l => l.filename)
                         .Title("File");
                     columns.Bound(l => l.serial_num)
                         .Title("Serial #");
                     columns.Bound(l => l.do_num)
                         .Title("Delivery Order #");
                     columns.Bound(l => l.co_num)
                         .Title("Order #");
                     columns.Bound(l => l.co_line)
                         .Title("Order Line");
                     columns.Bound(l => l.co_release)
                         .Title("Release #");
                 })
     .Sortable(sorting => sorting.OrderBy(sort=>sort.Add(l=>l.LogDateTime).Descending()))
     .Filterable()
     .Groupable()
     .Pageable(page => page.PageSize(10))
      )
       
@Html.Telerik().ScriptRegistrar()

Controller:
public ActionResult Log()
{
    var ldb = new JDContainersEntities();
    var log = (from l in ldb.CustContainersLogs
               select l).AsEnumerable();
    return View(log);
}


I've attached the 3 different grid screen shots - (sorted asc, sorted desc, and unsorted).  Again, there's nothing earth shattering here. 

Using VS 2010 (Version 10.0.40219.1 SP1) , Telerik MVC - 2012.2.607.340

-Sid.
0
Rosen
Telerik team
answered on 25 Jun 2012, 03:57 PM
Hello Sid,

I'm afraid that I'm unable to observe such behavior locally. I have attached a small test project could you please take a look maybe I'm missing something obvious.

Regards,
Rosen
the Telerik team
Check out the successor of Telerik MVC Extensions - Kendo UI for ASP.NET MVC - and deem it for new ASP.NET MVC development.
0
Sid
Top achievements
Rank 1
answered on 25 Jun 2012, 05:47 PM
Rosen,

Thanks. Yes your example worked fine. So, the question is why isn't my grid working when clearly the collection has the right # of records?

Here was my Linq To Entities query:
public ActionResult Log()
{
    var ldb = new JDContainersEntities();
    var log = (from l in ldb.CustContainersLogs
               select l).AsEnumerable();
    return View(log);
}

I changed it to:
public ActionResult Log()
{
    var ldb = new JDContainersEntities();
    var log = (from l in ldb.CustContainersLogs
               select l).ToList();
    return View(log);
}

This worked.  So what is in the AsEnumerable that isn't working with the paging/sorting?  It is a SqlServer 2000.  Or is it something in the EntityFramework?  There's a definite problem here.

Anyway, forcing it to enumerate with ToList() resolved the issue.

thanks,
-Sid.
Tags
Grid
Asked by
Sid
Top achievements
Rank 1
Answers by
Sid
Top achievements
Rank 1
Rosen
Telerik team
Share this question
or