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

[Solved] Change visibility of filterItem in hierarchy grid

7 Answers 198 Views
Grid
This is a migrated thread and some comments may be shown as answers.
koen van daalen
Top achievements
Rank 1
koen van daalen asked on 14 Aug 2009, 08:22 AM
Hello,

I'm trying to accomplish the following scenario with a  grid in hierachy model 3 levels deep using the OnNeedDataSource and OnDetailTableDataBind events. The grid can be refreshed with a button to get different data loaded using ajax and a forced databind() (server side) af refreshing the business layed on which the grid binds to.

1 - After load, no visiblitity of the filterrow
2 - Change visibility by using a radio button 
3 - changing preferably client side.
4 - after refreshing data the state of the filterrow should be preserved.
5 - on expanding the detailtable the filteritem of the datatable should also have the same visibility status as its mastertabelview

So far i've tried several soltutions, found here in this forum, but non of them worked for this scenario. 

i've written this piece of javascript to enable of disable the filters client side and this works.

       function showFilterItem() { 
            var grid = $find("<%= RadGrid1.ClientID %>"); 
            grid.get_masterTableView().showFilterItem(); 
            //get all detail tables in the hierarchy 
            var detailTablesArray = grid.get_detailTables(); 
 
 
            for (var x = 0; x < detailTablesArray.length; x++) { 
                detailTablesArray[x].showFilterItem(); 
            } 
        } 
        function hideFilterItem() { 
            var grid = $find("<%= RadGrid1.ClientID %>"); 
            grid.get_masterTableView().hideFilterItem(); 
            //get all detail tables in the hierarchy 
            var detailTablesArray = grid.get_detailTables(); 
 
            for (var x = 0; x < detailTablesArray.length; x++) { 
                detailTablesArray[x].hideFilterItem(); 
            } 
        } 
      
Please advice.

7 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 14 Aug 2009, 10:15 AM
Hello,

Since client side settings does not persist on postbacks, a suggestion would be to call these client functions again from the grid's PreRender server event using the RegisterStartUpScript property of the ScriptManager, based on the selected item of the RadioButtonList, so that the client settings are persisted on postbacks as well. 

If this does not help, you could achieve the same functionality on the server side, by accessing the filter row and then hiding/showing  it based on the RadioButton's selected item.

Thanks
Princy.
0
koen van daalen
Top achievements
Rank 1
answered on 14 Aug 2009, 11:39 AM
Hello Princy,

Thanks for your quick reply.
I'm afraid I do not fully understand what you are proposing.
Could you send me an example of houw thi can be acomplished?
0
koen van daalen
Top achievements
Rank 1
answered on 18 Aug 2009, 07:50 AM
I'm still trying to figure this out.
I've abandoned the Clientside method as this gives me to much problems trying to synchonise the data client and server side as the client side doesn't survive a postback

My current approach works except for the detail tables part.
onprerender i execute the following code:
protected override void OnPreRender(EventArgs e)  
        {  
            base.OnPreRender(e);  
              
            GridFilterVisisble(RadGrid1, RadioYes.Checked);  
        }  
 

 
 
 internal void GridFilterVisisble(RadGrid grid, bool visible)  
        {  
            GridItem[] items = grid.MasterTableView.GetItems(GridItemType.FilteringItem);  
            if ((items != null) && (items.GetLength(0) > 0))  
            {  
                items[0].Visible = visible;  
            }  
            if (grid.MasterTableView.HasDetailTables)  
            {  
                foreach (var DetailTabel in grid.MasterTableView.DetailTables)  
                {  
                    GridItem[] DetailTableFilteringItems = DetailTabel.GetItems(GridItemType.FilteringItem);  
                    if ((DetailTableFilteringItems != null) && (DetailTableFilteringItems.GetLength(0) > 0))  
                    {  
                        DetailTableFilteringItems[0].Visible = visible;  
                    }  
                }  
            }  
        } 
This works for the mastertableview, but doesn't for the detail tables.
The Collection of DetailTabelFilteringItems doesn't contain any data. So it can not set the visibility to false or true.

I also tryied to use the AllowFilteringByColumn propery of the grid, but this only works after another postback. So it is not an option

Does anybody have an idea how to enable/disable the filter row for a detail table (filteringItem) in code behind?
0
Shinu
Top achievements
Rank 2
answered on 18 Aug 2009, 11:29 AM
Hi,

Try the following approach to set the visibility of the filtering item for the detail table.

CS:
 
protected override void OnPreRender(EventArgs e) 
    { 
        base.OnPreRender(e); 
 
        GridFilterVisisble(RadGrid1, RadioYes.Checked); 
    } 
 
    void GridFilterVisisble(RadGrid grid, bool visible) 
    { 
        if (grid.MasterTableView.HasDetailTables) 
        { 
            
            for (int i=0; i<= grid.MasterTableView.DetailTables.Count-1; i++) 
            { 
                GridTableView childTable = (GridTableView)grid.MasterTableView.DetailTables[i]; 
                childTable.AllowFilteringByColumn = visible; 
            } 
        } 
        grid.Rebind(); 
 
    }  


Thanks
Shinu
0
koen van daalen
Top achievements
Rank 1
answered on 18 Aug 2009, 12:46 PM
Thanks shinu for your sugestion.
However the constant rebind for data on prerender has as a sideeffect that one is unable to expand to any detailtable!.

i've however adopted your idea and modified it.
I've now got it working, but with some downsides.
- i still need a postback.
- after changing the visibility all explanded detailtables are collapsed because of the rebind.
- gids with lots of data have a very slow response to changing the visibility of the filteritems of the grid. especialy if you'd compare this solution to the client side version.

Here is my code:
       internal void GridFilterVisisble(RadGrid grid, bool visible)  
        {  
            bool visibilityChanged = false;  
 
            if (grid.MasterTableView.HasDetailTables)  
            {  
                for (int i = 0; i <= grid.MasterTableView.DetailTables.Count - 1; i++)  
                {  
                    GridTableView childTable = (GridTableView)grid.MasterTableView.DetailTables[i];  
                    if (childTable.AllowFilteringByColumn != visible)  
                    {  
                        childTable.AllowFilteringByColumn = visible;  
                        visibilityChanged = true;  
                    }  
                }  
                                
            }  
            //Rebind grid if the visibility has changed. This enforces an update for the detailtables and collapes all detailtables  
            if (visibilityChanged) grid.Rebind();  
 
 
            // Change visibility of mastertabel filters  
            GridItem[] items = grid.MasterTableView.GetItems(GridItemType.FilteringItem);  
            if ((items != null) && (items.GetLength(0) > 0))  
            {  
                items[0].Visible = visible;  
            }  
        } 

Do you have another suggestion wich does'nt have these downsides?

Thanks.
Koen
0
Shinu
Top achievements
Rank 2
answered on 19 Aug 2009, 06:01 AM
Hi Koen,

Can you try with the following approach and see whether it is helpful.

CS:
 
 protected override void OnPreRender(EventArgs e) 
    { 
        base.OnPreRender(e); 
 
        GridFilterVisisble(RadGrid1, RadioYes.Checked); 
    } 
 
    void GridFilterVisisble(RadGrid grid, bool visible) 
    { 
         
        GridItem[] items = grid.MasterTableView.GetItems(GridItemType.FilteringItem); 
        if ((items != null) && (items.GetLength(0) > 0)) 
            items[0].Visible = visible; 
          
 
        foreach (GridDataItem item in RadGrid1.MasterTableView.Items) 
        { 
            if (item.Expanded) 
            { 
                GridTableView childTable = (GridTableView)item.ChildItem.NestedTableViews[0]; 
                GridItem[] DetailTableFilteringItems = childTable.GetItems(GridItemType.FilteringItem); 
                if ((DetailTableFilteringItems != null) && (DetailTableFilteringItems.GetLength(0) > 0)) 
                    DetailTableFilteringItems[0].Visible = visible; 
                 
            } 
        } 
 
    }  


Regards
Shinu
0
koen van daalen
Top achievements
Rank 1
answered on 19 Aug 2009, 06:44 AM
Shinu,

A very big thanks for your solution! It works brilliantly! It seems odd to me to not have a standard method to enable/disable filters on runtime by a single method, but thats life.

I've modified your code to support 3 levels in the hierarchy
 internal void GridFilterVisisble(RadGrid grid, bool visible)  
        {  
 
            GridItem[] items = grid.MasterTableView.GetItems(GridItemType.FilteringItem);  
            if ((items != null) && (items.GetLength(0) > 0))  
                items[0].Visible = visible;  
 
 
            foreach (GridDataItem item in grid.MasterTableView.Items)  
            {  
                if (item.Expanded)  
                {  
                    GridTableView childTable = (GridTableView)item.ChildItem.NestedTableViews[0];  
                    GridItem[] DetailTableFilteringItems = childTable.GetItems(GridItemType.FilteringItem);  
                    if ((DetailTableFilteringItems != null) && (DetailTableFilteringItems.GetLength(0) > 0))  
                        DetailTableFilteringItems[0].Visible = visible;  
                      
                    foreach (GridDataItem item2 in childTable.Items)  
                    {  
                        if (item2.Expanded)  
                        {  
                            GridTableView childTableLevel2 = (GridTableView)item2.ChildItem.NestedTableViews[0];  
                            GridItem[] DetailTableLevel2FilteringItems = childTableLevel2.GetItems(GridItemType.FilteringItem);  
                            if ((DetailTableLevel2FilteringItems != null) && (DetailTableLevel2FilteringItems.GetLength(0) > 0))  
                                DetailTableLevel2FilteringItems[0].Visible = visible;  
                        }  
                    }  
 
                }  
            }  
 
        } 

Again,
Thanks a lot.
Tags
Grid
Asked by
koen van daalen
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
koen van daalen
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Share this question
or