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

Apply specific header filter from code behind

1 Answer 13 Views
This is a migrated thread and some comments may be shown as answers.
Top achievements
Rank 1
Jonathan asked on 16 Mar 2021, 06:05 PM

I have a RadGrid on my page that I use as a selector, and via it's SelectedIndexChanged I wanna set some header filter on another grid.

Each time the selection is changed in the first RadGrid (rgPendingRequests) I want to adjust the header filter of rgResponsables and filter the result. The user must then be able to change the header filter as he wish, in case the filter returns nothing.

This is the grid I wanna apply the header filter to

    <GroupingSettings CaseSensitive="false"></GroupingSettings>
    <ClientSettings EnableRowHoverStyle="true" Selecting-AllowRowSelect="true" EnablePostBackOnRowClick="true" Scrolling-UseStaticHeaders="true" />
            <telerik:GridBoundColumn DataField="Prenom" Visible="true" HeaderStyle-Font-Bold="true" HeaderText="Prénom" UniqueName="Prenom" AutoPostBackOnFilter="true" CurrentFilterFunction="Contains" ShowFilterIcon="false" />
            <telerik:GridBoundColumn DataField="Nom" Visible="true" HeaderStyle-Font-Bold="true" HeaderText="Nom" UniqueName="Nom" AutoPostBackOnFilter="true" CurrentFilterFunction="Contains" ShowFilterIcon="false" />
            <telerik:GridBoundColumn DataField="Courriel" Visible="true" HeaderStyle-Width="250px" HeaderStyle-Font-Bold="true" HeaderText="Courriel" UniqueName="Courriel" AutoPostBackOnFilter="true" CurrentFilterFunction="Contains" ShowFilterIcon="false" />
            <telerik:GridBoundColumn DataField="Telephone" Visible="true" HeaderStyle-Width="120px" HeaderStyle-Font-Bold="true" HeaderText="Téléphone" UniqueName="Telephone" AutoPostBackOnFilter="true" CurrentFilterFunction="Contains" ShowFilterIcon="false" />

Here is my code Behind:

Protected Sub rgPendingRequests_SelectedIndexChanged(sender As Object, e As EventArgs) _
Handles rgPendingRequests.SelectedIndexChanged
    Dim PrenomCol = rgResponsables.MasterTableView.GetColumnSafe("Prenom")
    PrenomCol.CurrentFilterFunction = GridKnownFunction.Contains
    PrenomCol.CurrentFilterValue = rgPendingRequests.SelectedValues("FirstName")
    Dim NomCol = rgResponsables.MasterTableView.GetColumnSafe("Nom")
    NomCol.CurrentFilterFunction = GridKnownFunction.Contains
    NomCol.CurrentFilterValue = rgPendingRequests.SelectedValues("LastName")
End Sub

But even though the values appear in the header filter, the table is not filtered until I go to a header filter field and press enter...

I've tried everything I can think of, and could not make it work...

I could really use some pointer on what I'm doing wrong...

1 Answer, 1 is accepted

Sort by
Telerik team
answered on 19 Mar 2021, 02:43 PM

Hi Jonathan,

To be able to effectively filter the RadGrid you can either fire a filter command (How to Fire Command Events) or manipulate the filter expression manually (Operate with the FilterExpression Manually).

By firing the filter command you can only filter by one of the columns. The logic would be similar to the one below:

Protected Sub rgPendingRequests_SelectedIndexChanged(sender As Object, e As EventArgs)
    Dim PrenomCol = rgResponsables.MasterTableView.GetColumnSafe("Prenom")
    PrenomCol.CurrentFilterValue = rgPendingRequests.SelectedValues("OrderID")
    Dim filterItem As GridFilteringItem = CType(rgResponsables.MasterTableView.GetItems(GridItemType.FilteringItem)(0), GridFilteringItem)
    filterItem.FireCommandEvent("Filter", New Pair("Contains", "Prenom"))
End Sub

Manipulating the filter expression provides more flexibility but is often tricky and error-prone. For that approach please refer to the corresponding article linked above. You may also check out the implementation in the Multi-Selection RadComboBox for filtering grid code library sample

I hope that will help.

Kind regards,
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Asked by
Top achievements
Rank 1
Answers by
Telerik team
Share this question