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

RadGrid Filter issue when AutoPostbackOnFilter is true

1 Answer 284 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Waynen12
Top achievements
Rank 1
Waynen12 asked on 01 Nov 2012, 09:34 AM
Hi,

I've recently added functionality to one of my radgrids so that a Filter will be applied when the user presses Enter in the Filter text box. 
I have the CurrentFilterFunction set to "Contatins" on most columns and set the AutoPostbackOnFilter property to True.
I've also kept the Filter menu so that the user can choose another filter option.

One issue I've noticed is that if the user types in the the filter text box and then clicks on the menu to select another option, the default filter is immediately applied, which is a little annoying as then the grid has to apply the filter option chosen in the menu.

I've tried a few different ways to prevent this from happening without full success. One workaround was to set  the AutoPostbackOnFilter property to false and then set the FilterDelay to a high value. This works on all columns except datetime columns. 

<MasterTableView DataSourceID="ProjectsDS" ClientDataKeyNames="ID">
                <Columns>
                    <telerik:GridClientSelectColumn UniqueName="projectsSelect" Visible="false" />
                    <telerik:GridBoundColumn Visible="True" DataField="ID" UniqueName="ID" HeaderText="ID"
                        AutoPostBackOnFilter="False" CurrentFilterFunction="EqualTo" FilterDelay="60000" />
                    <telerik:GridBoundColumn DataField="Name" HeaderText="Name" UniqueName="Name" AutoPostBackOnFilter="False"
                        CurrentFilterFunction="Contains"  FilterDelay="60000" />
                    <telerik:GridBoundColumn DataField="CampaignName" HeaderText="Campaign" UniqueName="CampaignName">
                        <FilterTemplate>
                            <telerik:RadComboBox ID="FilterCombo" runat="server" AutoPostBack="false" AppendDataBoundItems="true"
                                DataSourceID="CampaignDS" DataTextField="Name" DataValueField="ID" OnClientSelectedIndexChanged="SelectedIndexChanged"
                                SelectedValue='<%# ((GridItem)Container).OwnerTableView.GetColumn("CampaignID").CurrentFilterValue %>'>
                                <Items>
                                    <telerik:RadComboBoxItem Text="No filters." Value="" />
                                </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("CampaignID", args.get_item().get_value(), "EqualTo");
                                    }
                                    function clientItemClicking(sender, args) {
                                        if (args.get_item().get_value() === "NoFilter") {
                                            var target = args.get_targetElement();
                                            var filterBox = target.parentNode.getElementsByTagName("input")[0];
                                            filterBox.value = "";
                                        }
                                    }                                  
                                </script>
                            </telerik:RadScriptBlock>
                        </FilterTemplate>
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="CampaignID" HeaderText="CampaignID" UniqueName="CampaignID"
                        Display="false" />
                    <telerik:GridBoundColumn DataField="FrameworkName" HeaderText="Framework" UniqueName="FrameworkName"
                        AutoPostBackOnFilter="False" CurrentFilterFunction="Contains" FilterDelay="60000"/>
                    <telerik:GridBoundColumn DataField="ProjectBaseName" HeaderText="Template" UniqueName="ProjectBaseName"
                        AutoPostBackOnFilter="False" CurrentFilterFunction="Contains" FilterDelay="60000"/>
                    <telerik:GridBoundColumn DataField="StatusDisplayValue" HeaderText="Status" UniqueName="StatusDisplayValue"
                        AutoPostBackOnFilter="False" CurrentFilterFunction="Contains" FilterDelay="60000"/>
                    <telerik:GridDateTimeColumn DataField="StartDate" HeaderText="Start Date" UniqueName="StartDate"
                        DataFormatString="{0:d}" AutoPostBackOnFilter="True" CurrentFilterFunction="EqualTo" FilterDelay="60000">
                    </telerik:GridDateTimeColumn>
                    <telerik:GridDateTimeColumn DataField="EndDate" HeaderText="End Date" UniqueName="EndDate"
                        DataFormatString="{0:d}" AutoPostBackOnFilter="True" CurrentFilterFunction="EqualTo">
                    </telerik:GridDateTimeColumn>
                    <telerik:GridBoundColumn DataField="ExternalID" HeaderText="External ID" UniqueName="ExternalID"
                        AutoPostBackOnFilter="False" CurrentFilterFunction="Contains" FilterDelay="60000"/>
                    <telerik:GridTemplateColumn DataField="IsArchived" HeaderText="Archived" UniqueName="IsArchived"
                        Visible="false" GroupByExpression="IsArchived Group By IsArchived">
                        <HeaderTemplate>
                            <asp:CheckBox ID="chkArchivedSelectAll" OnCheckedChanged="chkArchivedSelectAll_CheckedChanged"
                                AutoPostBack="true" runat="server" TextAlign="Right" Text=" Archived" />
                        </HeaderTemplate>
                        <ItemTemplate>
                            <asp:CheckBox ID="IsArchived" Checked='<%# Bind("IsArchived") %>' runat="server" />
                        </ItemTemplate>
                    </telerik:GridTemplateColumn>
                </Columns>
            </MasterTableView>

Is there a way to cancel the default Filter when the user clicks on the menu but also allow the user to press enter to apply the filter? I have noticed that on all of the demos of this functionality on this site, the Filter menu is removed from columns that have AutoPostBackOnFilter set to True. Is there an issue with using both together?

Thanks.

1 Answer, 1 is accepted

Sort by
0
Accepted
Marin
Telerik team
answered on 06 Nov 2012, 09:31 AM
Hello,

 Mixing the two filtering options is indeed a not very well supported scenario in the grid. By default in addition to pressing enter the filtering is also triggered when the change or blur event of the filter textbox fires. That's why when you click on the filter menu the textbox automatically blurs and triggers filtering. I'm afraid that there's no easy way workaround this behavior unless you define your own filter template and apply the desired features there.

All the best,
Marin
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
Waynen12
Top achievements
Rank 1
Answers by
Marin
Telerik team
Share this question
or