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

Grid will not bind correctly post filter (combo) selection

2 Answers 213 Views
Filter
This is a migrated thread and some comments may be shown as answers.
vidya
Top achievements
Rank 1
vidya asked on 12 Jun 2017, 04:55 PM

I have attached 2 files. An aspx page and a code behind vb page. I am trying to apply filter by implementing filter template. I have a radcombobox that filters the radgrid. 

Datasource for the radgrid is a dataset defined in aspx.vb. There are 2 tables in the dataset

Radcombobox datasource is a datatable from the above dataset defined in aspx.vb.

Trying to rebind the radgrid after the radcombobox selection both in code behind and on aspx via JS. 

1) using the following lines in cmbStateSelectedIndexChanged event does not rebind the grid.

 gv_MainStatusDynamic.MasterTableView.FilterExpression = e.Value<br>  filterItem.FireCommandEvent("Filter", New Pair("Contains", e.Value))<br>  gv_MainStatusDynamic.Rebind()

 

2) using FilterExpression in radgrid prerender does not rebind the grid

If isFiltered Then<br>            If rg_dynamic.MasterTableView.FilterExpression <> "0" Then<br>            Dim filterItem As GridFilteringItem = TryCast(TryCast(sender, RadComboBox).NamingContainer, GridFilteringItem)<br>            Dim aCombo As RadComboBox = TryCast(filterItem.FindControl("cmbState"), RadComboBox)<br>            rg_dynamic.MasterTableView.FilterExpression = Session("StateVal")<br>            rg_dynamic.MasterTableView.Rebind()<br>            End If<br>        End If

 

3) using filtering in aspx page does not rebind grid.

<telerik:RadScriptBlock ID="RadScriptBlock1" runat="server"><br>                                           <script type="text/javascript"><br>                                               function SelectedIndexChanged(sender, args)<br>                                               {<br>                                                   var tableView = $find("<%# TryCast(Container, GridItem).OwnerTableView.ClientID %>");<br>                                                   tableView.filter("State", args.get_item().get_value(), "EqualTo");<br>                                               }<br>                                           </script><br>                                       </telerik:RadScriptBlock>

 

In my first and second cases after I select a state and I do rg_dynamic.MasterTableView.Rebind(), the cmbState will not hold the selected value.

In my third case applying just that code to filter the grid on aspx side (that is commenting filter expression code in grid prerender and combobox selected index changed server side events) will hold the selected value. 

I have the datasource available for both grid and combox box on my server side. The grid will not rebind post filtered value. I came across an example on your forum pages http://demos.telerik.com/aspnet-ajax/grid/examples/functionality/filtering/filter-templates/defaultcs.aspx
But it is not helping me.

Any help on this is appreciated.

 

Here is my aspx.vb

Protected Sub rg_dynamic_NeedDataSource(sender As Object, e As GridNeedDataSourceEventArgs) Handles rg_dynamic.NeedDataSource<br>        rg_dynamic.DataSource = GetData()<br>    End Sub<br> <br> Private Function GetData() As DataSet<br>        Using oConn As SqlConnection = New SqlConnection(GenConn())<br>            'Gets dataset object<br>        End Using<br>    End Function<br> <br> Protected Sub rg_dynamic_ItemCreated(sender As Object, e As GridItemEventArgs) Handles rg_dynamic.ItemCreated<br>        If TypeOf e.Item Is GridFilteringItem Then<br>            Dim filterItem As GridFilteringItem = DirectCast(e.Item, GridFilteringItem)<br>            Dim cmbState As RadComboBox = DirectCast(filterItem("State").FindControl("cmbState"), RadComboBox)<br>            cmbState.SelectedValue = e.Item.OwnerTableView.GetColumn("State").CurrentFilterValue<br>            RefreshStateCombo(cmbState) <br>        End If<br>    End Sub<br> <br>  Protected Sub RefreshStateCombo(ByVal stCombo As RadComboBox)<br>        Dim SprocData As DataSet = GetData()<br>        Dim oDbDS As New DataBaseUtils2<br>        Dim StateDate As DataView = SprocData.Tables(0).DefaultView<br>        Dim dtStatedata As DataTable = StateDate.Table()<br>        stCombo.DataSource = StateDate<br>        stCombo.DataTextField = dtStatedata.Columns(1).ToString() 'name of the state<br>        stCombo.DataValueField = dtStatedata.Columns(0).ToString() 'StateCompID<br>    End Sub<br> <br> <br> Protected Sub rg_dynamic_PreRender(sender As Object, e As EventArgs) Handles rg_dynamic.PreRender<br>        If isFiltered Then<br>            If rg_dynamic.MasterTableView.FilterExpression <> "0" Then<br>            Dim filterItem As GridFilteringItem = TryCast(TryCast(sender, RadComboBox).NamingContainer, GridFilteringItem)<br>            Dim aCombo As RadComboBox = TryCast(filterItem.FindControl("cmbState"), RadComboBox)<br>            rg_dynamic.MasterTableView.FilterExpression = Session("StateVal")<br>            rg_dynamic.MasterTableView.Rebind()<br>            End If<br>        End If<br>    End Sub<br> <br>  Private isFiltered As Boolean = false<br>  Protected Sub cmbStateSelectedIndexChanged(sender As Object, e As RadComboBoxSelectedIndexChangedEventArgs) <br>        If e.Value <> "0" Then<br>            isFiltered = True<br>            Session("StateVal") = e.Value<br>        End If<br>       'Dim filterItem As GridFilteringItem = TryCast(TryCast(sender, RadComboBox).NamingContainer, GridFilteringItem)<br>        'filterItem.OwnerTableView.GetColumn("StateCompID").CurrentFilterValue = e.Value ''CAPTURE THIS VALUE in a property<br>        'rg_dynamic.MasterTableView.FilterExpression = e.Value<br>        'filterItem.FireCommandEvent("Filter", New Pair("EqualTo", e.Value))<br>        ' rg_dynamic.Rebind()<br>    End Sub

 

 

Here is my aspx

<Telerik:Radgrid ID="rg_dynamic" runat="server" DataKeyNames="StateCompID" EnableLinqExpressions="false" <br>                            BorderStyle="Solid" CellSpacing="0" BorderWidth="1px" AllowAutomaticDeletes="false" AllowMultiRowSelection="false"<br>                        AllowAutomaticInserts="false" AllowAutomaticUpdates="false" AutoGenerateColumns="False" AllowFilteringByColumn="true"<br>                            AllowSorting="True" GridLines="None" AllowPaging="false" Width="100%" MasterTableView-EnableColumnsViewState="false"><br>                            <br>                           <MasterTableView ><br>                            <Columns><br>                            <br>                                <telerik:GridBoundColumn DataField="StateCompID" Visible="False"  HeaderText="StateCompID" <br>                                    ItemStyle-HorizontalAlign="Left" ReadOnly="True" UniqueName="StateCompID" <br>                                    SortExpression="StateCompID"> </telerik:GridBoundColumn><br>                                <br>                         <br>                                <telerik:GridBoundColumn DataField="State" HeaderText="State" SortExpression="State" HeaderStyle-Width="175" UniqueName="State" AllowFiltering="true" AutoPostBackOnFilter="true"><br>                                   <FilterTemplate><br>                                        <telerik:RadComboBox RenderMode="Lightweight" ID="cmbState" AutoPostBack="true" AutoPostBackOnFilter="true" <br>                                            Width="200px" AppendDataBoundItems="true" SelectedValue='<%# TryCast(Container, GridItem).OwnerTableView.GetColumn("State").CurrentFilterValue%>'<br>                                            runat="server" OnClientSelectedIndexChanged="SelectedIndexChanged" OnSelectedIndexChanged="cmbStateSelectedIndexChanged" ><br>                                            <Items><br>                                                <telerik:RadComboBoxItem Text="All" Value="0" /><br>                                            </Items><br>                                        </telerik:RadComboBox><br>                                       <telerik:RadScriptBlock ID="RadScriptBlock1" runat="server"><br>                                           <script type="text/javascript"><br>                                               function SelectedIndexChanged(sender, args)<br>                                               {<br>                                                   var tableView = $find("<%# TryCast(Container, GridItem).OwnerTableView.ClientID %>");<br>                                                   tableView.filter("State", args.get_item().get_value(), "EqualTo");<br>                                               }<br>                                           </script><br>                                       </telerik:RadScriptBlock><br>                                    </FilterTemplate><br>                                </telerik:GridBoundColumn><br>                                <telerik:GridBoundColumn DataField="Company" HeaderText="Company Type" ReadOnly="True" SortExpression="Company" UniqueName="Company"<br>                                    ItemStyle-HorizontalAlign="Center"  AllowFiltering="false" ShowFilterIcon="false"><br>                                    <br>                                </telerik:GridBoundColumn><br>                            </Columns><br>                               </MasterTableView><br>                            <HeaderContextMenu CssClass="GridContextMenu GridContextMenu_Default"><br>                        </HeaderContextMenu><br>                       
 </Telerik:Radgrid>

2 Answers, 1 is accepted

Sort by
0
vidya
Top achievements
Rank 1
answered on 12 Jun 2017, 08:22 PM

I have tried to select from dataset and apply the expression to rebind the grid inside the grid pre-render event. Not sure if I am doing this right. 

In the combo selected index changed event I am saving the text(name of the state) to session variable instead of stateCompID as I was doing it earlier. But the grid still does not rebind. 

Dim SprocData As DataSet = GetData()<br>                Dim items = (From p In SprocData.Tables(0).AsEnumerable()<br>                Select New With {.ID = p.Field(Of Integer)("StateCompID"),<br>                                .Name = p.Field(Of String)("State")}).ToList()<br>                Dim filtered = items.Where(Function(x) x.Name.Contains(Session("StateVal"))).ToList()<br>                gv_MainStatusDynamic.MasterTableView.FilterExpression = filtered.ToString<br>                gv_MainStatusDynamic.MasterTableView.Rebind()
0
Eyup
Telerik team
answered on 16 Jun 2017, 05:32 AM
Hi Vidya,

The following live sample you mentioned should work as expected:
http://demos.telerik.com/aspnet-ajax/grid/examples/functionality/filtering/filter-templates/defaultcs.aspx

Also, you can check the first sample provided in the following post for an actual demonstration:
http://www.telerik.com/forums/how-to-persist-dropdownlist-selected-index-and-value-on-postback-from-radgrid-filtertemplate#GW3MyQLmVEmy8XzsmrHzeQ

In addition, I am also sending a VB sample.

Regards,
Eyup
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Filter
Asked by
vidya
Top achievements
Rank 1
Answers by
vidya
Top achievements
Rank 1
Eyup
Telerik team
Share this question
or