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

EnableCustomBinding and GroupBy

17 Answers 278 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.
Jason Walker
Top achievements
Rank 1
Jason Walker asked on 23 Mar 2010, 09:25 PM
Forgive me if this is a known issue, but it appears that you cannot use EnableCustomBinding with Grouping in the current version.

I've identified the problem being in GridActionAttribute.OnActionExecuting (this is reflected code, not the actual source code):

public void OnActionExecuting(ActionExecutingContext filterContext) 
    if (filterContext.ActionParameters.ContainsKey(this.ActionParameterName)) 
    { 
        GridCommand command2 = new GridCommand(); 
        command2.Page = filterContext.Controller.ValueOf<int>(GridUrlParameters.CurrentPage); 
        command2.PageSize = filterContext.Controller.ValueOf<int>(GridUrlParameters.PageSize); 
        GridCommand command = command2; 
        string from = filterContext.Controller.ValueOf<string>(GridUrlParameters.OrderBy); 
        command.SortDescriptors.AddRange<SortDescriptor>(GridDescriptorSerializer.Deserialize<SortDescriptor>(from)); 
        string input = filterContext.Controller.ValueOf<string>(GridUrlParameters.Filter); 
        command.FilterDescriptors.AddRange<IFilterDescriptor>(FilterDescriptorFactory.Create(input)); 
        filterContext.ActionParameters[this.ActionParameterName] = command; 
    } 
 

Notice that it deserializes all the required parts of GridCommand except for GroupBy.  I've fixed this in my own code, but figured you guys may want to fix this in the next release.

17 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 24 Mar 2010, 11:00 AM
Hello Jason Walker,

Thank you for reporting this problem. We have fixed it right away!

Regards,
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.
0
Lincoln Quinan
Top achievements
Rank 1
answered on 26 Mar 2010, 07:37 PM
I have the same issue ?

There is any code that I can download to solve this ?
0
Emmanuel Morales
Top achievements
Rank 2
answered on 29 Mar 2010, 10:04 PM
I'm running into the same issue. When will the fix be made public?
0
Atanas Korchev
Telerik team
answered on 30 Mar 2010, 08:12 AM
Hello,

The fix is incorporated in the current internal build. However only licensed developers can download it. For open source - you can check the attachment in this forum thread.

Regards,
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.
0
Dean J
Top achievements
Rank 1
answered on 13 Apr 2010, 07:45 PM
The build seems to fix the issue of serialization but there is another problem when grouping with custom binding.

The grid does not create the collapsible/uncollapsible nodes and it mis-aligns the data and grid columns. I can easily reproduce this
in the Telerik.Mvc.Examples project. Simply add the Groupable() method in the view and group in the grid. Is there a solution for this?

Thanks,
Dean J
0
Jason Walker
Top achievements
Rank 1
answered on 13 Apr 2010, 08:53 PM
Dean: Does whatever you are using to implement Custom Binding actually implement grouping?
0
Dean J
Top achievements
Rank 1
answered on 14 Apr 2010, 12:25 AM
Yes indeed... Basically we are moving over services that bring back only the collection needed to drive the grid results. To me this would seem to be a common scenario.
0
Atanas Korchev
Telerik team
answered on 14 Apr 2010, 08:50 AM
Hi Dean J,

I cannot reproduce the grouping issue you are mentioning in all online examples that have grouping enabled. Do you mean that the custom binding example does not work with grouping? If yes - indeed currently the custom binding example does not have grouping implemented.

Regards,
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.
0
Lincoln Quinan
Top achievements
Rank 1
answered on 14 Apr 2010, 02:10 PM
In a few days, I will post some extensions that me and my friend Juan implemented on the Telerik grid to help the implementation on CustomBinding. We are testing the extensions now, and we can use filtering, sorting and grouping with a few lines of code.

An example:

[GridAction(EnableCustomBinding = true)] 
public ActionResult Index(GridCommand command) 
    return View(command.List<TUser>(30)); 

Where the List is an extension method that have GridCommand and PageSize as parameters.

I expect to release the code in google code today or tomorrow.
It will be awesome to have the feedback of you guys.

Regards,
Lincoln
0
Dean J
Top achievements
Rank 1
answered on 14 Apr 2010, 11:03 PM
Sorry, I should have explain more. I downloaded the source which has the Telerik Examples in it. I modified the CustomBinding View to enable grouping. From there I would get the behaviour I described.

    That said, It looks like the way the Custom Binding works, It may be up to the implementor of the custom binding to present the data in a shape the grid can understand when displaying grouping. So, my question now is there a helper or extensions method I can use to shape the data for grouping.


Thanks for your help,

Dean J

0
Jason Walker
Top achievements
Rank 1
answered on 14 Apr 2010, 11:18 PM
Dean, see ToGridModel, an extension method on IQueryable<T> in the Telerik.Web.Mvc.Extensions namespace.
0
Dean J
Top achievements
Rank 1
answered on 14 Apr 2010, 11:46 PM
Hi Jason,
     That is was we implemented for the solution but it did not seem correct. We had to hard code it to look at page one all the time because we do not have GridState when implementing custom binding. We where thinking of writing a extension method that would take a command object to achieve the same result. Maybe that is what Lincoln is implemented. I look forward to his extension implementation for Custom Binding.

Thanks,
Dean J
0
Jason Walker
Top achievements
Rank 1
answered on 14 Apr 2010, 11:50 PM
You don't need GridState to call ToGridModel

public static GridModel Apply<T>(this GridCommand command, IQueryable<T> data) 
        { 
            var sortDescriptors = command.SortDescriptors ?? new List<SortDescriptor>(); 
            var groupDescriptors = command.GroupDescriptors ?? new List<GroupDescriptor>(); 
            var filterDescriptors = command.FilterDescriptors ?? new List<IFilterDescriptor>(); 
 
            foreach (var sortDescriptor in sortDescriptors) 
                sortDescriptor.Member = GetSortMember(sortDescriptor.Member); 
             
            foreach (var groupDescriptor in groupDescriptors) 
                groupDescriptor.Member = GetSortMember(groupDescriptor.Member); 
             
            return data.ToGridModel(command.Page, command.PageSize, sortDescriptors, filterDescriptors, groupDescriptors); 
        } 

This is my extension method on GridCommand.  Nevermind what GetSortMember does, that's my bit of custom stuff, which is why I had to EnableCustomBinding to begin with.
0
Dean J
Top achievements
Rank 1
answered on 14 Apr 2010, 11:59 PM
That is correct. This is where I should have explained futher. Our services only bring back a page of data at a time. So, if there are 4000 line items, we bring back enough records to satisfy one page. If the command.page is looking at page 2 lets say, then the result would be no items. That is why we had to hard code to page one. We are looking for an override that did not use paging and just shapes the data that is giving to it.

Thanks,
Dean J.
0
Juan Lopes
Top achievements
Rank 1
answered on 17 Apr 2010, 04:09 AM
Hi, as Lincoln said before, we were working on a set of extensions to enable using Telerik with partially implemented LINQ providers (e.g.: NHibernate's one). We have finished a first working version. It can create a meta expression, that works on an IQueryable<T> and returns another one.

The code itself is made to create expressions able to be serialized (and sent over the wire) and to work with NHibernate Linq provider, but the whole idea can be incorporated to any use you want. The implementation is very similar to ExpressionVisitor class, provided by Microsoft.

Sadly, we had an issue with the GroupBy using CustomBinding. To workaround, we modified the grid source code a little bit. The whole source code (including the modified Telerik's one), as well as the nightly built binaries and an example can be downloaded at:

http://code.google.com/p/simple-telerik-extensions
0
jessenaiman
Top achievements
Rank 1
answered on 30 Jun 2010, 04:33 PM
I followed his advice and added

.Groupable(settings => 
            { 
 
                settings.Groups(groups => 
                { 
                    groups.Add(o => o.ShipName); 
                }); 
                settings.Enabled(true); 
            }) 

to the CustomBinding.aspx page and when you select paging everything gets thrown off. In this case grouping is not being applied. I have a serious issue with grouping not working and the view being thrown off when an ajax call is made. Please advise a resolution .
0
Luis
Top achievements
Rank 1
answered on 07 Jan 2012, 03:59 PM
Finally I got it!

With the help of the guys on this thread I'm proud to say that I came to a satisfactory result, pluggable in any type of MVC application without much difficulty and almost none in the settings.

I published the project on Bitbucket and Nuget, please take a look and send me some feedbacks.

https://bitbucket.org/Lunadie/telerikmvcgridcustombindinghelper/wiki/Home 

https://nuget.org/packages/TelerikMvcGridCustomBindingHelper  
Tags
Grid
Asked by
Jason Walker
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Lincoln Quinan
Top achievements
Rank 1
Emmanuel Morales
Top achievements
Rank 2
Dean J
Top achievements
Rank 1
Jason Walker
Top achievements
Rank 1
Juan Lopes
Top achievements
Rank 1
jessenaiman
Top achievements
Rank 1
Luis
Top achievements
Rank 1
Share this question
or