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

[Solved] Grid grouping with custom ajax binding

1 Answer 65 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.
Dustin
Top achievements
Rank 1
Dustin asked on 27 Jan 2011, 08:44 PM
I am using a grid with custom ajax binding.  Paging, binding, etc. all work great, until I add in grouping.  In the sample application, if I remove lines 16-22 of Index.cshtml, this is when it works fine.  But, if I keep the grouping in, then the first two columns data show up in the first two (blank header) columns of the table, where the grouping information should be.  The two actual header columns, Name and Number, are then on top of blank columns. 

What am I missing?

I am using Windows 7 Pro, VS 2010, Entity Framework CTP5, MVC 3, with Telerik MVC extensions version 2010.3.1318 on IE 8 for this.

1 Answer, 1 is accepted

Sort by
0
Dustin
Top achievements
Rank 1
answered on 31 Jan 2011, 04:41 PM
Follow up question:
I have gotten this to work using the ToGridModel method in the Telerik.Web.Mvc.Extensions.QueryableExtensions class.  My controller code now looks like this:
[HttpPost]
[GridAction(EnableCustomBinding = true)]
public JsonResult Select(GridCommand command)
{
    var service = new MyService();
    var pageIndex = command.Page == 0 ? 1 : command.Page;
    var pageSize = command.PageSize == 0 ? 10 : command.PageSize;
    int totalCount;
 
    IEnumerable<MyModel> models = service.SelectModels(pageIndex, pageSize, out totalCount);
 
    GridModel gridModel =
        Telerik.Web.Mvc.Extensions.QueryableExtensions
        .ToGridModel(
            models.AsQueryable(),
            0,
            0,
            command.SortDescriptors,
            command.FilterDescriptors,
            command.GroupDescriptors);
 
    gridModel.Total = totalCount;
     
    return Json(gridModel);
}

So, my service does all the paging for me so that I only pull the records out of the database that I care about.  Then, I pass 0 into the ToGridModel method for page and pageSize parameters so that no paging is done in the method.  Sorting and Filtering are not enabled for my grid, so that doesn't affect anything.  So, basically I'm using this method to set up the grouping for me.

I assume this is not the way it is supposed to be done.  Can someone please push me in a different direction?  Do I need an implementation of the grouping logic in my own code to handle this or is there another way I can hook into the Telerik code?  Thanks!

Tags
Grid
Asked by
Dustin
Top achievements
Rank 1
Answers by
Dustin
Top achievements
Rank 1
Share this question
or