Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Group by navigation property #16

Open
LandryDubus opened this issue Aug 2, 2015 · 0 comments
Open

Group by navigation property #16

LandryDubus opened this issue Aug 2, 2015 · 0 comments

Comments

@LandryDubus
Copy link

Hello,

I just discovered your solution and this is just the perfect thing for what I was trying to do with Kendo UI Grid in the new ASP.NET 5 MVC 6 framework.

I had to make a few changes in order for this to work with the new framework but in the end this is working quite good!

While trying many scenarios with this component, the only one for which I got an error is when I try to group a grid by a navigation property.

For instance, I have a grid listing addresses (a type of entity) that I want to group by country (another type of entity available as a navigation property in the address entity).
I get an error in the KendoGridEx expression composing when I try to specify the groupby clause like this for instance:

group: { field: "Country.Name", dir: "asc" }

I think this is just a scenario that was not intended to work in your component but I think this would be quite useful.

For now I ended up grouping by the navigation property's foreign key that I materialized in the Adress entity and then used an hidden column for this property in the grid with a groupheadertemplate to show the right property in the group header.

I defined this javascript function for use in the template:

function getCountryName(value) {
    var grid = $("#grid").data("kendoGrid");
    var view = grid.dataSource.view();
    for (var i = 0; i < view.length; i++) {
        if (view[i].value === value) {
            return view[i].items[0].Country.Name;
        }
    }
}

I specified the grouping like this:

group: { field: "Country_Id", dir: "asc" }

Here is the template I used:

{ field: "Country_Id", hidden: true, groupHeaderTemplate: "#=getCountryName(value)#" },
{ field: 'Country.Name', title: 'Country' },

If we could directly specify to group by a navigation property this would be a lot easier.

I only need to do this because I do not use a flattened ViewModel and the automapping options of your component. I work directly with the entities and so I got to work with the navigation properties.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant