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

NestedViewTemplate and Filtering

5 Answers 151 Views
Filter
This is a migrated thread and some comments may be shown as answers.
Oscar
Top achievements
Rank 1
Oscar asked on 23 Nov 2010, 07:58 PM
I wrote something that is very similar to this Demo:
http://demos.telerik.com/aspnet-ajax/grid/examples/hierarchy/nestedviewtemplatedeclarativerelations/defaultvb.aspx

The difference is my radgrid has sorting features enabled. After running a sort to narrow down the list, the rows no longer expand. It triggers the event, and seems to do everything else properly but does not expand the rows so that specific data is available to the user.

I would appreciate any feedback and will offer my code if it's necessary. I thought that it would be something to do with the code behind but after working on this for a day and a half I am almost certain it's some setting I missed in the aspx page. I'm still researching this issue as I work but I could really use a hint or three.

Thanks,
Oscar

5 Answers, 1 is accepted

Sort by
0
Oscar
Top achievements
Rank 1
answered on 23 Nov 2010, 10:29 PM
After doing some more work on this I am going to post a few snippets of where I think the error could be at this point. I have tried using a DetailTable with a GridTableView inside the radgrid. My original iteration was with the nestedtemplateview, (I prefer this version it looked nicer and was exactly what we wanted for the application I am building). I am having the same exact issue with both of these attempts. The rows expand and show the view, but once a filter has been applied to the main RadGrid it does not expand the row. 

<MasterTableView AutoGenerateColumns="False"
    DataSourceID="SqlDataSource1"
    DataKeyNames="USER_ID"
    AllowMultiColumnSorting="true"
    Width="100%">

<telerik:RadGrid ID="RadGrid1" runat="server"
    AllowFilteringByColumn="True"
    AllowPaging="True"
    AllowSorting="True"
    DataSourceID="SqlDataSource1"
    GridLines="None"
    Skin="Outlook"
    PageSize="100"
    EnableLinqExpressions="False"
    ShowGroupPanel="True"
    ShowStatusBar="True"
    AutoGenerateColumns="false">
    <ClientSettings AllowColumnsReorder="True" ReorderColumnsOnClient="True"
        AllowDragToGroup="True">
        <Selecting AllowRowSelect="True" />
        <Scrolling AllowScroll="True" UseStaticHeaders="True" />
    </ClientSettings>


    Protected Sub RadGrid1_PreRender(ByVal o As Object, ByVal e As EventArgs) Handles RadGrid1.PreRender
 
        If Not RadGrid1.MasterTableView.FilterExpression Is String.Empty Then
 
            FilterSetter()
        End If
    End Sub
 
    Private Sub FilterSetter()
 
        sqlLocationFilter.SelectCommand = "SELECT DISTINCT [DBOL] FROM [DBO]" & " WHERE " & RadGrid1.MasterTableView.FilterExpression.ToString() & " ORDER BY [Location]"
        sqlDepartmentFilter.SelectCommand = "SELECT DISTINCT [DOBD] FROM [DBO]" & " WHERE " & RadGrid1.MasterTableView.FilterExpression.ToString() & " ORDER BY [DBOD]"
        sqlOfficeFilter.SelectCommand = "SELECT DISTINCT [DBOO] FROM [DBO]" & " WHERE " & RadGrid1.MasterTableView.FilterExpression.ToString() & " ORDER BY [DBOO]"
 
        RadGrid1.MasterTableView.Rebind()
    End Sub
 
    Protected Sub ResetFiltersButton_OnClick(ByVal o As Object, ByVal e As EventArgs)
 
        RadGrid1.MasterTableView.FilterExpression = String.Empty
 
        For Each column As GridColumn In RadGrid1.MasterTableView.RenderColumns
 
            If TypeOf column Is GridBoundColumn Then
 
                Dim boundColumn As GridBoundColumn = TryCast(column, GridBoundColumn)
                boundColumn.CurrentFilterValue = String.Empty
            End If
        Next
 
        RadGrid1.Rebind()
    End Sub
 
    Protected Sub RadGrid1_ItemCommand(ByVal o As Object, ByVal e As GridCommandEventArgs) Handles RadGrid1.ItemCommand
 
        If e.CommandName = Telerik.Web.UI.RadGrid.ExpandCollapseCommandName Then
 
            Dim item As GridItem
 
            For Each item In e.Item.OwnerTableView.Items
 
                TestExpandEvent.Visible = True
                If item.Expanded And item IsNot e.Item Then
 
                    item.Expanded = False
                End If
            Next
        End If
    End Sub
End Class

I hope this is enough to help,

Oscar
0
Oscar
Top achievements
Rank 1
answered on 24 Nov 2010, 06:45 PM
I've found the cause of my problem but how to fix the issue is escaping me. I can't quite figure out what is stopping it from extending the rows.

When the FilterSetter function runs as it is the rows don't expand.
Protected Sub RadGrid1_PreRender(ByVal o As Object, ByVal e As EventArgs) Handles RadGrid1.PreRender
    If Not RadGrid1.MasterTableView.FilterExpression Is String.Empty Then
        FilterSetter()
    End If
End Sub
Private Sub FilterSetter()
    SqlLocationFilter.SelectCommand = "SELECT DISTINCT [Location] FROM [View_PhoneList_Debra] " & "WHERE " & RadGrid1.MasterTableView.FilterExpression.ToString() & " ORDER BY [Location]"
    SqlDepartmentFilter.SelectCommand = "SELECT DISTINCT [Department] FROM [View_PhoneList_Debra] " & "WHERE " & RadGrid1.MasterTableView.FilterExpression.ToString() & " ORDER BY [Department]"
    RadGrid1.MasterTableView.Rebind()
End Sub

When I take the RadGrid1.MasterTableView.Rebind() line out of the code it still gives me the ability to expand the rows. But my combobox filters aren't getting set properly anymore.

I had thought that this could help a bit, I did some testing and the event does fire and run through this function properly so I know it gets through here. I've still not found a way to solve this problem yet:

Protected Sub RadGrid1_ItemCommand(ByVal o As Object, ByVal e As GridCommandEventArgs) Handles RadGrid1.ItemCommand
    If e.CommandName = Telerik.Web.UI.RadGrid.ExpandCollapseCommandName Then
        Dim item As GridItem
        For Each item In e.Item.OwnerTableView.Items
            If item.Expanded And item IsNot e.Item Then
                item.Expanded = False
            End If
        Next
    End If
End Sub

0
Accepted
Veli
Telerik team
answered on 26 Nov 2010, 08:46 AM
Hello Oscar,

The PreRender event is breaking your scenario. In the FilterSetter() method (called if the FilterExpression is not empty - meaning if there is a filter applied) calls RadGrid.MasterTableView.Rebind().  Rebinding is an operation that recreates all grid items in their default state. This means that, after rebinding, your items are collapsed. So what happens:

1. You filter the grid. Now with a non-empty FilterExpression, RadGrid will rebind on every PreRender.
2. You try to expand an item. The ItemCommand event is fired in RadGrid and the item is internally expanded, the detail table / nested view is databound.
3. In PreRender, RadGrid is rebound, as you have applied a filter that causes FilterSetter(). At this point, your expanded item is gone, because the grid items are recreated.

Hope this clarifies the scenario.

Veli
the Telerik team
Browse the vast support resources we have to jumpstart your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
Oscar
Top achievements
Rank 1
answered on 29 Nov 2010, 10:21 PM

When I run the page without the Rebind() method call in my PreRender() method I get the desired filtering behavior, for the most part. We want the ComboBoxes to have a cascading data feature. When I set AppendDataBoundItems=”false” this does the trick but the user can no longer set the ComboBox to “ALL”. I put in a button to clear all the filters and that isn’t too bad. The problem I am running into now is when I have the ComboBoxes set and type in a first or last name that is invalid the page does nothing but says there is an error. I went to http://demos.telerik.com/aspnet-ajax/grid/examples/programming/filtertemplate/defaultvb.aspx and when you set the country to Argentina then set the filter for Is Promoted to yes the page loads http://demos.telerik.com/ErrorPageResources/error.aspx?aspxerrorpath=/aspnet-ajax/grid/examples/programming/filtertemplate/defaultvb.aspx this error. I thought that it was just a random connection but apparently your filters have the same issue that I am trying to overcome. I am guessing that you guys are aware of this issue, are there any suggestions on something that could be done? Or am I limited to trying to make the possibility of this happening as small as possible?

 

I also would like to have the ComboBoxes show all values that are on the same level as the current selection. For an example if it was States and Cities, and I had selected California for the state and Los Angeles for the City, I would like to click on the city combobox and have it display all cities in the state of California. Where would be a place to start looking for that possibility?

0
Subhashini
Top achievements
Rank 1
answered on 09 Aug 2016, 09:25 PM

I have the exact same issue , that I am discussing here:

http://www.telerik.com/forums/data-not-populating-on-expand---several-tables-at-a-level#G3uttvczDUKrP5d77Bzh2A

I am not sure how to rebind the inner grids or show the inner grids after applying filter.

Any help is appreciated.

Thanks.

Tags
Filter
Asked by
Oscar
Top achievements
Rank 1
Answers by
Oscar
Top achievements
Rank 1
Veli
Telerik team
Subhashini
Top achievements
Rank 1
Share this question
or