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

Filter on column where Display=false

4 Answers 81 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Per
Top achievements
Rank 1
Per asked on 10 Mar 2011, 02:27 PM
Hi!

I have a RadGrid with 6 columns.
Filter is enabled on all columns.

In my first column, I have used a FilterTemplate to display a DropDown containing all my product categories.

Some of the categories have the same name, but different id's.
When I select a category from the dropdown, a client filtering is performed on the category name.
Now the grid contains all products where the category name is equal to the name in the drop down.

I want the filtering to occure on the value of the dropdown and not the name.
I tried to add a BoundColumn containing the CategoryId and filter on that column. This works fine when the column is visible, but when I set it to Display="false", no filtering occurs.

Any suggestions?

Regards
Per

4 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 11 Mar 2011, 11:09 AM
Hello Per,

Here is the code that I tried in my application and it is working at my end. Pease check this and see if it helps.

ASPX:
<Columns>
    <telerik:GridBoundColumn DataField="CategoryId" UniqueName="CategoryId"
        Display="false">
    </telerik:GridBoundColumn>
    <telerik:GridBoundColumn AllowFiltering="true" DataField="CategoryName"
         UniqueName="CategoryName">
        <FilterTemplate>
            <telerik:RadComboBox ID="RadComboBox1" runat="server" DataSourceID="SqlDataSource1"
                DataTextField="CategoryName" DataValueField="CategoryId"
SelectedValue='<%# ((GridItem)Container).OwnerTableView.GetColumn("CategoryId").CurrentFilterValue %>'
                OnClientSelectedIndexChanged="SelectedIndexChanged">
            </telerik:RadComboBox>
            <telerik:RadScriptBlock ID="RadScriptBlock1" runat="server">
 
                <script type="text/javascript">
                    function SelectedIndexChanged(sender, args) {
                        var tableView = $find("<%# ((GridItem)Container).OwnerTableView.ClientID %>");
                        tableView.filter("CategoryId", args.get_item().get_value(), "EqualTo");
                    }
                </script>
 
            </telerik:RadScriptBlock>
        </FilterTemplate>
    </telerik:GridBoundColumn>
</Columns>

Thanks,
Princy.
0
Per
Top achievements
Rank 1
answered on 13 Mar 2011, 11:06 AM
Hi

It's working :) Thanks!

The only problem I have now is that I want to add a empty row in the drop down so the user can clear the selected aswell.

I have tried to just:
<Items>
  <telerik:RadComboBoxItem />
</Items>
But that doesnt seem to work :(

Any suggestions?

Regards
Per
0
Accepted
Princy
Top achievements
Rank 2
answered on 14 Mar 2011, 10:24 AM
Hello Per,

Try the following code and see if it works now.
ASPX:
        <FilterTemplate>
            <telerik:RadComboBox ID="RadComboBox1" runat="server" DataSourceID="SqlDataSource1"
                DataTextField="CategoryName" DataValueField="CategoryId"
SelectedValue='<%# ((GridItem)Container).OwnerTableView.GetColumn("CategoryId").CurrentFilterValue %>'
                OnClientSelectedIndexChanged="SelectedIndexChanged"
                AppendDataBoundItems="true">
            <Items>
        <telerik:RadComboBoxItem Text="nofilter" Value="nofilter" />
            </Items>
            </telerik:RadComboBox>
            <telerik:RadScriptBlock ID="RadScriptBlock1" runat="server">
                 <script type="text/javascript">
                    function SelectedIndexChanged(sender, args) {
                        var tableView = $find("<%# ((GridItem)Container).OwnerTableView.ClientID %>");
                        tableView.filter("CategoryId", args.get_item().get_value(), "EqualTo");
                    }
                </script>
             </telerik:RadScriptBlock>
        </FilterTemplate>

Thanks,
Princy.
0
Per
Top achievements
Rank 1
answered on 14 Mar 2011, 06:08 PM
Hi!

It works !!! :)

Thanks alot

//Per
Tags
Grid
Asked by
Per
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Per
Top achievements
Rank 1
Share this question
or