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

Server-side filtering using Navigation property

1 Answer 94 Views
GridView
This is a migrated thread and some comments may be shown as answers.
david mcintyre
Top achievements
Rank 1
david mcintyre asked on 02 Aug 2010, 08:13 PM

I get an error when I attempt to use the server-side filtering, as described in your demo at http://demos.telerik.com/silverlight/#GridView/DomainDataSource .

The problem is that I can't filter the gridview using navigation properties, and almost all the properties in my gridview are navigation properties.  I am able to bind the navigation properties in my grid, but when I click on the gridview's filter icon to filter by distinct values, I get an error "ArgumentException was unhandled by user code.  'Location.LocationName' is not a member of type 'MyApplication.Web.Models.Order'. 

Is it possible to rewrite the expression to navigate thru the navigation property?

Here's my slightly modified version of your demo code that retrieves the distinct values.  It still fails even after adding the "Includes".   The error occurs on the evaluation of propertyName in the last line of CreateSelectorExpression.

public List<DistinctValue> GetDistinctValues(string propertyName)
        {
            var list = new List<DistinctValue>();
            var values = this.ObjectContext.Orders
                .Include("Item")
                .Include("Location")
                .Include("Source")
                .Select(CreateSelectorExpression(propertyName)).Distinct();
            int i = 0;
            foreach (var value in values)
            {
                list.Add(new DistinctValue() { ID = i, Value = value });
                i++;
            }
  
            return list;
        }
  
        private static Expression<Func<ItemLocationSource, string>> CreateSelectorExpression(string propertyName)
        {
            var paramterExpression = Expression.Parameter(typeof(Order));
            return (Expression<Func<Order, string>>)Expression.Lambda(Expression.PropertyOrField(paramterExpression, propertyName), paramterExpression);
        }

Here's a snippet of the relevant client-side code in case you need it. 

<domainSvcs:DomainDataSource x:Name="OrdersDataSource"  AutoLoad="True" QueryName="GetOrders" PageSize="25" FilterOperator="Or">
                    <domainSvcs:DomainDataSource.DomainContext>
                        <MyDomainContextWeb:MyDomainContextDomainContext />
                    </domainSvcs:DomainDataSource.DomainContext>
                </domainSvcs:DomainDataSource>
                <telerikGridView:RadGridView x:Name="gridOrders" 
                                                                 CanUserReorderColumns="True" CanUserSortColumns="True" ItemsSource="{Binding Data, ElementName=OrdersDataSource}" AutoGenerateColumns="False"  
                                                                 IsBusy="{Binding IsBusy, ElementName=OrdersDataSource}" AutoExpandGroups="True" Filtering="gridOrders_Filtering" DistinctValuesLoading="gridOrders_DistinctValuesLoading"
                                                                 ScrollViewer.VerticalScrollBarVisibility="Visible"  AlternationCount="2" RowIndicatorVisibility="Collapsed" RowActivated="gridOrders_RowActivated"
                                                                 AlternateRowBackground="{StaticResource AlternateBGBrush}" GridLinesVisibility="Vertical"  CanUserInsertRows="False"  
                                                                 shared:GridViewColumnPicker.IsEnabled="True" CanUserDeleteRows="False" IsReadOnly="True"  >
  
                    <telerikGridView:RadGridView.Columns>
                        <telerikGridView:GridViewDataColumn Header="{Binding Path=ApplicationStrings.ItemID, Source={StaticResource ResourceWrapper}}" DataMemberBinding="{Binding Item.ItemID}" TextAlignment="Right" HeaderTextAlignment="Center" />
                        <telerikGridView:GridViewDataColumn Header="{Binding Path=ApplicationStrings.ItemName, Source={StaticResource ResourceWrapper}}" DataMemberBinding="{Binding Item.ItemName}" TextAlignment="Right" HeaderTextAlignment="Center" />
                        <telerikGridView:GridViewDataColumn Header="{Binding Path=ApplicationStrings.LocationID, Source={StaticResource ResourceWrapper}}" DataMemberBinding="{Binding Location.LocationID}" TextAlignment="Right" HeaderTextAlignment="Center" />
                        <telerikGridView:GridViewDataColumn Header="{Binding Path=ApplicationStrings.LocationName, Source={StaticResource ResourceWrapper}}" DataMemberBinding="{Binding Location.LocationName}" TextAlignment="Right" HeaderTextAlignment="Center" />
                        <telerikGridView:GridViewDataColumn Header="{Binding Path=ApplicationStrings.SourceID, Source={StaticResource ResourceWrapper}}" DataMemberBinding="{Binding Source.SourceID}" TextAlignment="Right" HeaderTextAlignment="Center" />
                        <telerikGridView:GridViewDataColumn Header="{Binding Path=ApplicationStrings.SourceName, Source={StaticResource ResourceWrapper}}" DataMemberBinding="{Binding Source.SourceName}" TextAlignment="Right" HeaderTextAlignment="Center" />
  
 </telerikGridView:RadGridView.Columns>
  
  
                </telerikGridView:RadGridView>
                <telerikData:RadDataPager x:Name="RadDataPager1"  Source="{Binding Data, ElementName=OrdersDataSource}" DisplayMode="FirstLastPreviousNextNumeric"  IsTotalItemCountFixed="True"  VerticalContentAlignment="Top" Grid.Row="1" />

1 Answer, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 06 Aug 2010, 07:04 AM
Hello,

You can create your own filtering control where you can put desired logic for server-side filtering. Please check this blog post for more info. 

Greetings,
Vlad
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
Tags
GridView
Asked by
david mcintyre
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Share this question
or