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

Cannot filter on EF datasource where Columns are FKs

1 Answer 36 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Tim
Top achievements
Rank 1
Tim asked on 22 Oct 2012, 03:27 PM

Using the below data, I can Sort but cannot filter on any of the columns which are populated based on a foreignKey.  As you can see in ietmsCreated, I'm only loading into my Filerting Combobox, those countries which are already associated with a given Recipientorganization.  This works fine, however, when I click on one of the countries in the Comboxbox, the Grid always refresehs and appears empty.

Ideas?

Private Sub RecipientsGrid_NeedDataSource(sender As Object, e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles RecipientsGrid.NeedDataSource
 
 Dim ctx As New DataEntities
 
 RecipientsGrid.DataSource = ctx.RecipientOrganizations.ToList
 
End Sub
    Private Sub RecipientsGrid_ItemCreated(sender As Object, e As Telerik.Web.UI.GridItemEventArgs) Handles RecipientsGrid.ItemCreated
 If TypeOf e.Item Is GridFilteringItem Then
            'CustomFilters
 
            Dim item As GridFilteringItem = CType(e.Item, GridFilteringItem)
  '** Country **
            Dim FilterCountry As RadComboBox = CType(item.FindControl("FilterCountry"), RadComboBox)
            Using ctx As New DataEntities
 
                With FilterCountry
                    .DataSource = ctx.RecipientOrganizations.Select(Function(x) x.Country).Distinct.ToList
                End With
                FilterCountry.Width = Unit.Pixel(80)
            End Using '** Country **
        End If
    End Sub

<telerik:GridBoundColumn DataField="Country.CountryName"
                         FilterControlAltText="Filter Country column" HeaderText="Country" HeaderStyle-Width="170" FilterControlWidth="170"
                         SortExpression="Country.CountryName" UniqueName="Country">
    <FilterTemplate>
        <telerik:RadComboBox ID="FilterCountry"  Height="100px" AppendDataBoundItems="true" DataValueField="CountryId"  DataTextField="CountryName"
                             SelectedValue='<%# TryCast(Container,GridItem).OwnerTableView.GetColumn("Country").CurrentFilterValue %>'
                             runat="server" OnClientSelectedIndexChanged="FilterCountryChanged" >
            <Items>
                <telerik:RadComboBoxItem Text="All" />
            </Items>
        </telerik:RadComboBox>
        <telerik:RadScriptBlock ID="CountryFilterScript" runat="server">
            <script type="text/javascript">
                function FilterCountryChanged(sender, args) {
                    var tableView = $find("<%# TryCast(Container,GridItem).OwnerTableView.ClientID %>");
                    tableView.filter("Country", args.get_item().get_value(), "EqualTo");
                }
            </script>
 
        </telerik:RadScriptBlock>                            
    </FilterTemplate>
</telerik:GridBoundColumn>



1 Answer, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 25 Oct 2012, 01:51 PM
Hello Tim,

Please examine the attached demo and then let me know whether the demonstrated approach is suitable for your scenario. You could run the website on your end, just add the binary files and attach the sample database.

Best regards,
Daniel
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
GridView
Asked by
Tim
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Share this question
or