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

[Solved] Filtering in Hierarchy

5 Answers 222 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Airad
Top achievements
Rank 1
Airad asked on 15 Jul 2009, 04:25 AM

aspx:

<telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" />
   
                <telerik:RadGrid ID="grdDashb2" runat="server" AllowFilteringByColumn="True"

                    AllowPaging="True" AllowSorting="True" GridLines="None" 
                    ShowGroupPanel="True" AutoGenerateColumns="False" 
                    OnNeedDataSource="grdDashb2_NeedDataSource"

                    OnItemCreated="grdDashb2_ItemCreated"

                    OnDataBound="grdDashb2_OnDataBound" 
                    OnItemCreated="grdDashb2_ItemCreated"

                    OnColumnCreated="grdDashb2_ColumnCreated"
                    OnPreRender="grdDashb2_PreRender">

<

MasterTableView HierarchyDefaultExpanded="false" HierarchyLoadMode="Client" AllowSorting="true" 

                        AllowPaging="true" DataKeyNames="TopicId,TopicParentId,TopicName,Tm" Width="100%" 
                        EditMode="EditForms" ClientDataKeyNames="TopicId">  
 
                        <SelfHierarchySettings ParentKeyName="TopicParentId" KeyName="TopicId" /> 
 
                        <Columns> 
                            <telerik:GridTemplateColumn UniqueName="TemplateEditColumn" AllowFiltering="false">  
                                <ItemTemplate> 
                                </ItemTemplate> 
                            </telerik:GridTemplateColumn> 
                              
                            <telerik:GridNumericColumn DataType="System.Decimal" DataField="Kmo" 
                                HeaderText="AFR" SortExpression="Kmo" /> 
                                  
                            <telerik:GridTemplateColumn DataField="Tm" UniqueName="Tm" HeaderText="Light">   
                                <FilterTemplate> 
                                    <telerik:RadComboBox ID="ARF_RadComboBox"  
                                        SelectedValue='<%# ((GridItem)Container).OwnerTableView.GetColumn("Tm").CurrentFilterValue %>'
                                        runat="server" 
                                        OnClientSelectedIndexChanged="TrafficlightColorIndexChanged">  
                                        <Items> 
                                            <telerik:RadComboBoxItem Text="All" /> 
                                            <telerik:RadComboBoxItem Text="item1" Value="item1"/>  
                                            <telerik:RadComboBoxItem Text="item2" Value="item2"/>  
                                            <telerik:RadComboBoxItem Text="item3" Value="item3"/>  
                                        </Items> 
                                    </telerik:RadComboBox> 
 
                                    <telerik:RadScriptBlock ID="RadScriptBlock1" runat="server">  
                                    <script type="text/javascript">  
                                    function TrafficlightColorIndexChanged(sender,args) {  
                                        var tableView=$find("<%# ((GridItem)Container).OwnerTableView.ClientID %>");  
                                        tableView.filter("Tm",args.get_item().get_value(),"EqualTo");  
                                    }  
                                    </script> 
                                    </telerik:RadScriptBlock> 
                                </FilterTemplate> 
                                  
                                <ItemTemplate> 
                                     
                                    <asp:Image ID="imgAFR" runat="server" ImageUrl='<%# ReturnUrl(Eval("Tm").ToString) %>'/> 
                                </ItemTemplate> 
                            </telerik:GridTemplateColumn> 
                        </Columns> 
 </MasterTableView> 

cs:

        protected
 void grdDashb2_PreRender(object sender, System.EventArgs e)  
        {  
            if (grdDashb2.MasterTableView.FilterExpression != string.Empty)  
            {  
                RefreshCombos();  
            }  
        }  
 
        protected void RefreshCombos()  
        {  
            grdDashb2.MasterTableView.FilterExpression = grdDashb2.MasterTableView.FilterExpression.ToString();  
            grdDashb2.MasterTableView.Rebind();  
        }  
 
        public string ReturnUrl(string Tm)  
        {  
            if (Tm != "" || Tm != string.Empty)  
            {  
                return "../Images/" + Tm;  
            }  
            else 
            {  
                return "../Images/blankgif.gif";  
            }  
        } 

Hi!

Me again!

I want to filter in a Hierarchy grid by "Tm"  column
<telerik:GridTemplateColumn DataField="Tm" UniqueName="Tm" HeaderText="Light">   

I follow this demo: http://demos.telerik.com/aspnet-ajax/grid/examples/programming/filtertemplate/defaultcs.aspx.

No Hierarchy, so good. 
But when I filter with Hierarchy , server error: Object reference not set to an instance of an object .

I don't konw whether there is some different when filter in Hierarchy or not?

Later I will post a screenshot to describe the situation more clearly.

Thank you!

Best wishes
Airad

5 Answers, 1 is accepted

Sort by
0
Airad
Top achievements
Rank 1
answered on 16 Jul 2009, 01:46 AM

screenshot :
http://p13.freepcn.cn/p.aspx?u=v20_p13_p_0907160940445832_0.jpg&click=1


filter by "Light"  column (DataField "Tm")

<telerik:GridTemplateColumn DataField="Tm" UniqueName="Tm" HeaderText="Light">   

Thanks!
0
Accepted
Pavlina
Telerik team
answered on 20 Jul 2009, 09:55 AM
Hello Airad,

Attached to this message is a simple runnable application that demonstrates the needed approach. Please give it a try and let me know if you have other questions or problems.

More information about  filter template is available in the following help article:
Filter template

All the best,
Pavlina
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Airad
Top achievements
Rank 1
answered on 21 Jul 2009, 08:20 AM
<DetailTables>  
                    <telerik:GridTableView DataKeyNames="OrderID" DataSourceID="AccessDataSource2" Width="100%" 
                        runat="server">  
                        <ParentTableRelation>  
                            <telerik:GridRelationFields DetailKeyField="CustomerID" MasterKeyField="CustomerID" />  
                        </ParentTableRelation>  
                        <Columns>  
                            <telerik:GridBoundColumn SortExpression="OrderID" HeaderText="OrderID" HeaderButtonType="TextButton" 
                                DataField="OrderID" UniqueName="OrderID">  
                            </telerik:GridBoundColumn>  
                            <telerik:GridBoundColumn SortExpression="OrderDate" HeaderText="Date Ordered" HeaderButtonType="TextButton" 
                                DataField="OrderDate" UniqueName="OrderDate">  
                            </telerik:GridBoundColumn>  
                            <telerik:GridBoundColumn SortExpression="EmployeeID" HeaderText="EmployeeID" HeaderButtonType="TextButton" 
                                DataField="EmployeeID" UniqueName="EmployeeID">  
                            </telerik:GridBoundColumn>  
                        </Columns>  
                    </telerik:GridTableView>  
</DetailTables> 

Thank you for the nice demo!

I think our Hierarchy grid code in an improper style caused this problem.

In fact, I'm just told to add a filter function into our Hierarchy grid page but this page is coded by others.  So I didn't check the Hierarchy  grid carefully.  I alway think some errors in filter code caused this problem.

Best Regards
Airad
0
Pavlina
Telerik team
answered on 23 Jul 2009, 01:08 PM
Hello Airad,

I am happy to hear that the provided project helped you to solve the problem.
Do not hesitate to contact us if other questions arise.

Regards,
Pavlina
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Airad
Top achievements
Rank 1
answered on 24 Jul 2009, 02:12 AM
:) Sure! Thanks again!

Regards
Airad
Tags
Grid
Asked by
Airad
Top achievements
Rank 1
Answers by
Airad
Top achievements
Rank 1
Pavlina
Telerik team
Share this question
or