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

Grid will not bind correctly post filter (combo) selection

1 Answer 43 Views
Grid
This is a migrated thread and some comments may be shown as answers.
vidya
Top achievements
Rank 1
vidya asked on 15 Jun 2017, 02:04 PM

Hi,

I am trying to apply filter by implementing filter template. I have a radcombobox that filters the radgrid. 

a) Datasource for the radgrid is a dataset defined in aspx.vb. There are 2 tables in the dataset
b) Radcombobox datasource is a datatable from the above dataset defined in aspx.vb.
c) 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

<code style="color: #000;">gv_MainStatusDynamic.MasterTableView.FilterExpression = e.Value<</code><code style="color: #069;font-weight: bold;">br</code><code style="color: #000;">>  filterItem.FireCommandEvent("Filter", New Pair("Contains", e.Value))<</code><code style="color: #069;font-weight: bold;">br</code><code style="color: #000;">>  gv_MainStatusDynamic.Rebind()</code>

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. 

 

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()

 

Any help on this is appreciated.

Thanks

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>       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() <br>        stCombo.DataValueField = dtStatedata.Columns(0).ToString()  <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>                        <br> </Telerik:Radgrid>

 

 

1 Answer, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 20 Jun 2017, 11:37 AM
Hello Vidya,

I've already replied to your query in the following thread:
http://www.telerik.com/forums/grid-will-not-bind-correctly-post-filter-(combo)-selection

I suggest that we continue our conversation on the mentioned thread.

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
Grid
Asked by
vidya
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Share this question
or