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

GroupByExpression & LINQ to SQL Sub-Object Member Properties

17 Answers 387 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Chris
Top achievements
Rank 1
Chris asked on 04 Jun 2008, 08:12 PM
Simply put, I am not able to group on a child object's property in my LINQ to SQL datasource.  I am able to bind, sort, and filter on the property but not group by it.  Here is the the template column in question.   Note: all works save the GroupByExpression.  I have yet to find a solution, some direction is welcome.

<telerik:GridTemplateColumn  
    HeaderText="DC" 
    SortExpression="Dc.Name" 
    UniqueName="DC" 
    GroupByExpression="Dc.Name [DC] Group By Dc.Name">  
    <EditItemTemplate> 
        <telerik:RadComboBox  
            ID="cboDc" 
            runat="server" 
            DataSourceID="ldsDcs" 
            DataValueField="DcID" 
            DataTextField="Name" 
            SelectedValue='<%# Bind("DcID") %>'>  
        </telerik:RadComboBox> 
    </EditItemTemplate> 
    <ItemTemplate> 
        <%# Eval("Dc.Name") %>&nbsp;  
    </ItemTemplate> 
</telerik:GridTemplateColumn> 

Error message received:

Line: 605
Char: 13
Error: Sys.WebForms.PageRequestManagerServerErrorException: Field
          Dc.Name not found in the source table. Please check the expression
          syntax.
Code: 0

Thanks,
Chris

17 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 05 Jun 2008, 06:44 AM
Hi Chris,

Have a look at the following help articles.
Basic grouping
Declarative definition

Shinu.




0
Scott
Top achievements
Rank 1
answered on 17 Jul 2008, 06:46 PM
Chris,
Did you ever find an answer to this. I looked at the help links listed by Shinu, but could not decipher a clear answer to the problem.

Scott
0
Chris
Top achievements
Rank 1
answered on 17 Jul 2008, 06:55 PM
Scott,

No the links did not address the issue.  I went a different direction.  Personally, I find it odd that you can sort and even bind to a child property but not group by that property.

I also find it odd that telerik choose not to group or sort by the display text on combo box columns vs the value property.  I have never had a case where the value was anything meaningful to the user, why sort and group by the value field that is not displayed to the user.  I always place IDs in the value field and display the human readable text in the text field, because I normalize my databases, and use either GUIDs or sequencial IDs.

I believe I went with a template column and had to do a bunch of coding to suport the grouping.

-chris
0
Scott
Top achievements
Rank 1
answered on 17 Jul 2008, 07:23 PM
Chris,

Thanks for the response. I was afraid that was going to be the answer. We're coding by the same standards you mentioned with respect to the value/display text. I agree, it is odd. We're you able to reference the child object's property when you switched to the template column? I found an example that uses the ItemDataBound event of the grid that allows us to get to the DataRowView, but I can't find the code to get to the underlying child object.

Scott
0
Scott
Top achievements
Rank 1
answered on 17 Jul 2008, 07:57 PM
Shinu,

Would you be able to elaborate on Telerik's reasoning for the behavior mentioned in this thread or at least elaborate on a solution to the proper declarative settings for using child objects in the group by expressions for the radGrid?
0
Vlad
Telerik team
answered on 18 Jul 2008, 05:04 AM
Hi guys,

Straight onto this issues:

@Chris
You cannot group, sort or filter on drop down columns text field due to the fact that the in most cases this field is not part of the grid data source.

@Scot
Unfortunatelly this functionality is not yet implemented. We will do our best to provide this as soon as possible.

Greetings,
Vlad
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Chris
Top achievements
Rank 1
answered on 18 Jul 2008, 01:18 PM
Shinu,

I can not believe I am hearing a programer say you can not do anything about a design requirement.  As a control developer, I have built grids that do just that, the grouping can be done after the data sources have been loaded, you do display the text field on the screen, so you have the data at some point.

It makes no sense to group, sort or filter by a non-visible attribute.  It also makes no sense for the control developer to push off a drop down list column that does not support the functionality of it's base column correctly, and if you think sorting, filtering, and grouping by the hidden field is correct functionality, think again.

I have developed a work around, and I am thinking of extending your control so that it behaves correctly, since my company has bought into your solution.  This issue, in my opinion weakens your product offering.

Thanks,
Chris
0
Chris
Top achievements
Rank 1
answered on 18 Jul 2008, 01:25 PM
Shinu,

With LINQ to SQL data sources, we have the parent data to our codes, so for example, i create a linq entity that has a code, and the code links to a description, in linq i can through dot notation, access that property, i do this with other databound columns and it works just fine, so with linq to sql datasources you have the text value for example

employee has a manager

employee linq entity looks like this

firstname
lastname
title
managerid
manager

in your grid, i can set a field to either managerid, or to manager.name

the issue is i want to allow the user to edit the record and have a dropdownlist of available managers, yet group by the manager.name, not managerid or manager.id

i should be able to specify in the column definition a group by expression of "manager.name" and data field of "managerid" and provide the datasource for the combobox, because in the grid you display a string not a combo control, the combo control is only rendered in edit mode.

i do not have more time to waist on this, i believe i have given you enough to provide a proper control solution, especially with linq datasources.

thanks
chris
0
Vlad
Telerik team
answered on 21 Jul 2008, 05:33 AM
I'm sorry Chris - I'm not Shinu :)

Feel free to post your workaround with DropDownColumn.

Kind regards,
Vlad
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
James Van Buren
Top achievements
Rank 2
answered on 17 Nov 2008, 05:17 PM
Is there are solution to this problem in newer release of Grid?
I am having the same issues, trying to SORT/FILTER/GROUP By Sub object via linq.
If it's not possible yet, will it ever? I can bind to the field, so why cant i sort by it?
0
Nikolay Rusev
Telerik team
answered on 21 Nov 2008, 08:11 AM
Hello James Van Buren,

Unfortunately grouping on nested properties is not currently supported in RadGrid. However you can achieve this functionality by adding extra hidden column which is bound to the property which you are using for grouping.

/for example/
<telerik:GridBoundColumn DataField="Customer.ContactName"    
  UniqueName="CustomerHidden" Visible="false">  
</telerik:GridBoundColumn> 
 

I've prepared sample application demonstrating this technic. You can find it attached to this post.

All the best,
Nikolay
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
James Van Buren
Top achievements
Rank 2
answered on 24 Nov 2008, 07:13 PM

Nikolay thanks for response..

Bu this will not let me do drag&drop column, right?

If im not mistaken, I cannot have another Template/Databound Column, and have it Group/Sort based on this hidden GridBoundColumn

Your solution will only allow me to have fixed grouping on page load, right? or i guess i can rework it with alternative, UI controls, like give user all columns and allow to pick the groub by columns from combo  for example, than repost and manipulate grouping, but that would be sort of lame, wouldnt it be?

0
Nikolay Rusev
Telerik team
answered on 26 Nov 2008, 04:58 PM
Hello James Van Buren,

You can create visible GridBoundColumn that has DataField and SortExpression nested object. Thus you'll be able to group on this nested property.
However if you need to set GroupExpression on nested property and you don't have column that is bound to this property you must use the approach explained in my previous post.

You can see example attached to this post.

Best wishes,
Nikolay
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
James Van Buren
Top achievements
Rank 2
answered on 10 Dec 2008, 04:08 PM
Thanks for all your replies and continious support. I think i got the sorting and Grouping work, but the filtering is still not working.

i have 2 databound columns:

 <telerik:GridBoundColumn DataField="Vendor.VendorNmbr" UniqueName="VendorNmbr" Visible="false" AllowFiltering="true" /> 
   
<telerik:GridBoundColumn DataField="Vendor.VendorNmbr" HeaderText="Vendor" Groupable="true" SortExpression="VendorID" ItemStyle-Width="70" FilterListOptions="VaryByDataType" DataType="System.String"/>  
                        

whenever i try to filter on Vendor column, i get this JS error:

Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerServerErrorException: Object reference not set to an instance of an object. 

not sure where to go from here.

PLease advise!


0
Nikolay Rusev
Telerik team
answered on 12 Dec 2008, 03:47 PM
Hello James,

I am afraid that I am not able to reproduce the issue on my end. It seems that the error is raised on client-side and I am not sure how this relates to RadGrid columns.
You can use FireBug or Fiddler to investigate the issue on your end.

However if the issues still arise I suggest you to create small runnable application and send it to us via formal support ticket. Thus we will be able to debug it locally.

I hope this helps.

All the best,
Nikolay
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Steve
Top achievements
Rank 1
answered on 19 Mar 2013, 11:55 AM
Is there still no way to achieve this with a GroupByExpression and Linq with a RadGrid?

The workaround is not so elegant and I was hoping to achieve this dynamically.
0
Radoslav
Telerik team
answered on 22 Mar 2013, 11:07 AM
Hi Steve,

The current version of RadGrid support grouping by inner property. I am sending you a simple example which demonstrates that.

I hope this helps.

Kind regards,
Radoslav
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Grid
Asked by
Chris
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Scott
Top achievements
Rank 1
Chris
Top achievements
Rank 1
Vlad
Telerik team
James Van Buren
Top achievements
Rank 2
Nikolay Rusev
Telerik team
Steve
Top achievements
Rank 1
Radoslav
Telerik team
Share this question
or