How to Reset Filter Template Combobox

6 posts, 0 answers
  1. Kosta
    Kosta avatar
    4 posts
    Member since:
    Jan 2013

    Posted 06 Feb 2013 Link to this post

    Hi,

    Is is possible to reach a Filtered Template Combobox outside the event

    Protected Sub RadGrid1_ItemCommand(ByVal source As Object, ByVal e As Telerik.WebControls.GridCommandEventArgs)

    My code for a FilterTemplate is
    <telerik:GridBoundColumn DataField="MeasuringPointName" FilterControlAltText="Filter MeasuringPointName column"
        HeaderText="Изм. т-ка" SortExpression="MeasuringPointName" UniqueName="MeasuringPointName" >
        <ItemStyle Wrap="False" />
        <FilterTemplate>
            <telerik:RadComboBox ID="RadComboBoxMeasuringPointName" DataSourceID="ObjectDataSourceMeasuringPointsNames" DataTextField="MeasuringPointName"
                DataValueField="MeasuringPointName" AppendDataBoundItems="true"  Width="100%" DropDownAutoWidth="Enabled"
                SelectedValue='<%# TryCast(Container,GridItem).OwnerTableView.GetColumn("MeasuringPointName").CurrentFilterValue %>'
                runat="server" OnClientSelectedIndexChanged="MeasuringPointNameIndexChanged">
                <Items>
                    <telerik:RadComboBoxItem Text="Всички" />
                </Items>
            </telerik:RadComboBox>
            <telerik:RadScriptBlock ID="RadScriptBlockMeasuringPointName" runat="server">
                <script type="text/javascript">
                    function MeasuringPointNameIndexChanged(sender, args) {
                        var tableView = $find("<%# TryCast(Container,GridItem).OwnerTableView.ClientID %>");
                        tableView.filter("MeasuringPointName", args.get_item().get_value(), "EqualTo");
                    }
                </script>
            </telerik:RadScriptBlock>
        </FilterTemplate>
    </telerik:GridBoundColumn>

    I have a RadComboBox and a RadButton which are used to fill SqlDataSource and invoke RadGrid.Prerender with RadGrid.Rebind(). I also use RadAjaxmanager with following code:
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" DefaultLoadingPanelID="RadAjaxLoadingPanel1">
           <AjaxSettings>
               </telerik:AjaxSetting>
               <telerik:AjaxSetting AjaxControlID="btnExecute">
                   <UpdatedControls>
                       <telerik:AjaxUpdatedControl ControlID="Panel1" />
                   </UpdatedControls>
               </telerik:AjaxSetting>
               <telerik:AjaxSetting AjaxControlID="MeasuringPointsDataGrid">
                   <UpdatedControls>
                       <telerik:AjaxUpdatedControl ControlID="Panel1" />
                   </UpdatedControls>
               </telerik:AjaxSetting>
           </AjaxSettings>
           <ClientEvents OnRequestStart="onRequestStart" />
       </telerik:RadAjaxManager>
       <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" Skin="Telerik"
           Transparency="30" meta:resourcekey="RadAjaxLoadingPanel1Resource1">
       </telerik:RadAjaxLoadingPanel>

    On first select everithing work correctly. I select item from FilterTemplate and filtering works correct. If I change the the criteria to be completed the RadGrid the FilterTemplate retains the old chosen value instead to change to "All".
    My idea is to handle

    btnExecute_Click(sender As Object, e As System.EventArgs) Handles btnExecute.Click
    event and inside it  any help would me more than welcome  to set the RadComboBoxMeasuringPointName SelectedIndex to 0. 

    Any help would me more than welcome. Thank you.

  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 06 Feb 2013 Link to this post

    Hi,

    I guess you want to access the RadComboBox inside the FilterTemplate in an external button click.

    VB:
    Protected Sub btnExecute_Click(sender As Object, e As EventArgs)
        Dim Radgrid1 As RadGrid = DirectCast(FindControl("RadGrid1"), RadGrid)
        For Each fitem As GridFilteringItem In Radgrid1.MasterTableView.GetItems(GridItemType.FilteringItem)
                'do your code here
            Dim combo As RadComboBox = DirectCast(fitem.FindControl("RadComboBoxMeasuringPointName"), RadComboBox)
        Next
    End Sub

    Thanks,
    Shinu.
  3. Kosta
    Kosta avatar
    4 posts
    Member since:
    Jan 2013

    Posted 06 Feb 2013 Link to this post

    Thank you so much for your answer.

    Your code works fine but didn't help me to deside my task. I miss something. All I want to do is to display all rows with data into RadGrid after FilterTemplate's Radcombobox selected index is changed to <> 0 and after that RadGrid is rebind i.e. fill with new data.

    At this time my Page looks like this pseudo table:

    [ZonesCheckedComboBox]  [btnExecute]
    Row   MeasuringPoint                         Other Data
              [FilterTemplateComboBox]
    1         1                                                ...
    2         2                                                ...
    3         1                                                ...
      
    after page is loaded and data is displayed into radGrid I change [FilterTemplateComboBox] value and click on [btnExecute] to execute RadGrid_PreRender. DataSource for my RadGrid Is ObjectDataSource is that is important. I select to filter only measuringpoint with value 1 and grid looks good

    [ZonesCheckedComboBox] [btnExecute]
    Row      MeasuringPoint                     Other Data
                 [FilterTemplateComboBox]
    1           1                                            ...
    3           1                                            ...

    After that I select new zones and click on [btnExecute] and here comes problem. My page look like
    [ZonesCheckedComboBox] [btnExecute]
    Row         MeasuringPoint                                 Other Data
                    [FilterTemplateComboBox]
    1             1                                                         ...
    1             1                                                         ...
    I need manualy to change [FilterTemplateComboBox] to display all rows not just those that are left from the old filter.

    My question is is it possible to set a [FilterTemplateComboBox] to display all data  after every click on [btnExecute] and fill radGrid with data.

    Thank you so much.
  4. Angel Petrov
    Admin
    Angel Petrov avatar
    1102 posts

    Posted 11 Feb 2013 Link to this post

    Hi Kosta,

    In order to achieve the desired functionality you can clear the filters manually in the button click event handler like shown in this code snippet:
    Protected Sub btnExecute_Click(sender As Object, e As System.EventArgs) Handles btnExecute.Click
            Dim Radgrid1 As RadGrid = DirectCast(FindControl("RadGrid1"), RadGrid)
            For Each fitem As GridFilteringItem In Radgrid1.MasterTableView.GetItems(GridItemType.FilteringItem)
                'do your code here
                Dim combo As RadComboBox = DirectCast(fitem.FindControl("RadComboBoxMeasuringPointName"), RadComboBox)
                Radgrid1.MasterTableView.FilterExpression = ""
                Radgrid1.Rebind()
            Next
        End Sub

    And later in the OnItemDataBound event set the first item in the combo as selected:
    Protected Sub RadGrid1_ItemDataBound(sender As Object, e As Telerik.Web.UI.GridItemEventArgs) Handles RadGrid1.ItemDataBound
            If TypeOf e.Item Is GridFilteringItem Then
                If RadGrid1.MasterTableView.FilterExpression = "" Then
                    DirectCast(DirectCast(e.Item, GridFilteringItem).FindControl("RadComboBoxMeasuringPointName"), RadComboBox).Items(0).Selected = True
                End If
            End If
        End Sub

    This should do the trick. The approach is also demonstrated in the project attached.

    All the best,
    Angel Petrov
    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.
  5. Mina
    Mina avatar
    6 posts
    Member since:
    Mar 2012

    Posted 24 Apr 2013 Link to this post

    Thank you. Better late than never but I have a too much tasks to do. In my case it was nessesury to write an extra code to button's click event. Here is it. Thank you again.

    Protected Sub btnExecute_Click(sender As Object, e As System.EventArgs) Handles btnExecute.Click
        For i As Integer = 0 To RadGrid1.Columns.Count - 1
            RadGrid1.Columns(i).ResetCurrentFilterValue()
        Next
        RadGrid1.MasterTableView.FilterExpression = ""
        RadGrid1.MasterTableView.Rebind()
    End Sub
  6. yassin wakeel
    yassin wakeel avatar
    1 posts
    Member since:
    May 2010

    Posted 20 Dec 2017 in reply to Mina Link to this post

    It works fine, thank you
Back to Top