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

RadGrid Self-referencing Hierarchy - filtering problem

5 Answers 199 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mark Perry
Top achievements
Rank 1
Mark Perry asked on 21 May 2010, 04:20 PM

We are passing a DataTable to our radGrid via the code behind. When the grid initally loads the data displays correctly. As soon as we filter, it ignores the Filter Expression and filters all the data not by the initial Hierarchy.

        rgCategories.EnableLinqExpressions = false;  
            rgCategories.MasterTableView.FilterExpression = @"([ParentCategoryId] = 0)"


Here is our SQL code

SELECT DISTINCT [MEPDB].[MEPBUS].[CATEGORY].[category_id] AS [CategoryId], [MEPDB].[MEPBUS].[CATEGORY].[parent_category_id] AS [ParentCategoryId], [MEPDB].[MEPBUS].[CATEGORY].[levelAS [Level], [MEPDB].[MEPBUS].[CATEGORY].[nameAS [Name], [MEPDB].[MEPBUS].[CATEGORY].[description] AS [Description], [MEPDB].[MEPBUS].[CATEGORY].[home_message] AS [HomeMessage], [MEPDB].[MEPBUS].[CATEGORY].[email_address] AS [EmailAddress], [MEPDB].[MEPBUS].[CATEGORY].[create_date] AS [CreateDate], [MEPDB].[MEPBUS].[CATEGORY].[update_date] AS [UpdateDate], [MEPDB].[MEPBUS].[CATEGORY].[create_by] AS [CreateBy], [MEPDB].[MEPBUS].[CATEGORY].[update_by] AS [UpdateBy], [MEPDB].[MEPBUS].[CATEGORY].[is_submission_allowed] AS [IsSubmissionAllowed], [MEPDB].[MEPBUS].[CATEGORY].[is_enabled] AS [IsEnabled], [MEPDB].[MEPBUS].[CATEGORY].[is_render_home_page] AS [IsRenderHomePage], [MEPDB].[MEPBUS].[CATEGORY].[is_protected] AS [IsProtected] FROM [MEPDB].[MEPBUS].[CATEGORY]  WHERE ( ( ( [MEPDB].[MEPBUS].[CATEGORY].[parent_category_id] IS NOT NULL))) ORDER BY [MEPDB].[MEPBUS].[CATEGORY].[parent_category_id] ASC,[MEPDB].[MEPBUS].[CATEGORY].[nameASC 

Markup Code

 <telerik:RadGrid  
                                        ID="rgCategories" 
                                        runat="server" 
                                        AllowPaging="True" 
                                        AutoGenerateColumns="false" 
                                        AllowSorting="True" 
                                        CommandItemDisplay="Top" 
                                        GridLines="None" 
                                        PageSize="20" 
                                        AllowFilteringByColumn="true" 
                                        GroupingSettings-CaseSensitive="false" 
                                        OnNeedDataSource="rgCategories_NeedDataSource" 
                                        OnPreRender="rgCategories_PreRender" 
                                        OnItemCommand="rgCategories_ItemCommand" 
                                    > 
                                        <MasterTableView DataKeyNames="CategoryId,ParentCategoryId" HierarchyLoadMode="Client" Width="100%">  
                                           <Columns> 
                                                <telerik:GridBoundColumn  
                                                    DataField="CategoryID" 
                                                    HeaderText="<%$Resources:meis,Labels_ID%>" 
                                                    SortExpression="CategoryID" 
                                                /> 
                                                <telerik:GridHyperLinkColumn  
                                                    DataNavigateUrlFields="CategoryID"   
                                                    HeaderText="<%$Resources:meis,Labels_Name%>" 
                                                    DataNavigateUrlFormatString="CategoryEdit.aspx?CategoryID={0}"   
                                                    DataType="System.String" 
                                                    DataTextField="Name" 
                                                    DataTextFormatString="{0}" 
                                                    SortExpression="Name" 
                                                /> 
                                                <telerik:GridBoundColumn  
                                                    DataField="Description" 
                                                    HeaderText="<%$Resources:meis,Labels_Description%>" 
                                                    SortExpression="Description" 
                                                /> 
                                                <telerik:GridHyperLinkColumn  
                                                    HeaderText="<%$Resources:meis,Labels_AddSubCategory %>" 
                                                    AllowFiltering="false" 
                                                    DataNavigateUrlFields="CategoryID" 
                                                    DataNavigateUrlFormatString="CategoryEdit.aspx?ParentCategoryID={0}" 
                                                    Text="<%$Resources:meis,Labels_AddSubCategory %>" 
                                                /> 
                                            </Columns> 
                                            <RowIndicatorColumn> 
                                                <HeaderStyle Width="20px"></HeaderStyle> 
                                            </RowIndicatorColumn> 
                                            <ExpandCollapseColumn> 
                                                <HeaderStyle Width="20px"></HeaderStyle> 
                                            </ExpandCollapseColumn> 
                                            <SelfHierarchySettings  
                                                ParentKeyName="ParentCategoryId" 
                                                KeyName="CategoryId" 
                                            /> 
                                        </MasterTableView> 
                                    </telerik:RadGrid> 

5 Answers, 1 is accepted

Sort by
0
Radoslav
Telerik team
answered on 27 May 2010, 08:22 AM
Hello Mark,

Could you please elaborate a bit more on your scenario. In which event do you set the RadGrid.MasterTableView.FilterExpression property? Also could you please confirm that you use the advanced data binging with NeedDataSource event. Additionally could you please post the code from your code behind. Thus I will be able to gather more details about your scenario and provide you with more to-the-point answer.

Looking forward for your reply.

Best wishes,
Radoslav
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Mark Perry
Top achievements
Rank 1
answered on 27 May 2010, 04:58 PM

Sure, we add the data in the page_Load and we use the NeedDataSourceEvent

We set the RadGrid.MasterTableView.FilterExpression in the Page_Load but not in the NeedDataSourceEvent

// this is our Page_LoadEvent         
protected override void PopulateUI()  
        {  
            if (!IsPostBack)  
            {  
                BindCategories();  
            }  
        }  
 
        private void BindCategories()  
        {  
            // Next line is needed per Telerik documentation to filter out children from root display  
#if IncludeRoot  
            rgCategories.EnableLinqExpressions = true;  
            rgCategories.MasterTableView.FilterExpression = @"it[""ParentCategoryID""] = Convert.DBNull";
#else  
            rgCategories.EnableLinqExpressions = false;  
            rgCategories.MasterTableView.FilterExpression = @"([ParentCategoryId] = 0)";
#endif  
            this.GetCategoryList();  
            this.rgCategories.DataSource = this._Categories;  
            this.rgCategories.DataBind();  
        }     
 
private void GetCategoryList()  
        {  
            SortExpression sort;
#if !IncludeRoot  
            PredicateExpression filter = new PredicateExpression();
#endif  
 
            this._Categories = new TlCategoryTypedList();
#if !IncludeRoot  
            filter.Add(new FieldCompareNullPredicate(CategoryFields.ParentCategoryId, nulltrue));
#endif  
            sort = new SortExpression();  
            sort.Add(CategoryFields.ParentCategoryId | SortOperator.Ascending);  
            sort.Add(CategoryFields.Name | SortOperator.Ascending);
#if !IncludeRoot  
            TypedListHelper.Fill(this._Categories, filter, sort);
#else  
            TypedListHelper.Fill(this._Categories, sort);
#endif  
        }  
 
        protected void rgCategories_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)  
        {  
            this.GetCategoryList();  
            this.rgCategories.DataSource = this._Categories;  
        }  
 
 

 

 

0
Radoslav
Telerik team
answered on 01 Jun 2010, 12:15 PM
Hello Mark,

Could you please try moving your logic for filtering from Page_Load event to RadGrid.PreRender event. For more information please check out the following online documentation article.:
http://www.telerik.com/help/aspnet-ajax/grdapplyingdefaultfilteroninitialload.html

Also, please check this article which explains how to operate with the FilterExpression of RadGrid manually.
Additionally If the issue still exist, could you please send us a small runnable project which demonstrates the issue. You could open a formal support ticket from your Telerik account and attach a ZIP file there.Thus we will be able to we debug the project and provide you with more to-the-point answer.

All the best,
Radoslav
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Mark Perry
Top achievements
Rank 1
answered on 07 Jun 2010, 09:32 PM
I submitted a support ticket with a project that shows the problem we are having.
0
Radoslav
Telerik team
answered on 09 Jun 2010, 03:31 PM
Hello Mark,

When you perform filtering its overrides the FilterExpression set into the Page_Load event. To achieve the desired functionality you need to concatenate the current FilterExpression with the @" AND ([ParentCategoryId] = 0)". For example:
protected void rgCategories_PreRender(object sender, EventArgs e)
{
     if (rgCategories.MasterTableView.FilterExpression == "")
     {
         rgCategories.MasterTableView.FilterExpression = @"([ParentCategoryId] = 0)";
     }
     else
     {
         rgCategories.MasterTableView.FilterExpression += @" AND ([ParentCategoryId] = 0)";
     }
  
     rgCategories.Rebind();
}

Also I am sending you a simple example.

Additionally I noticed that you have opened a duplicate post on the same matter. Please, refer to the other support ticket post for additional information. To avoid duplicate posts, I suggest you continue the communication there.

Best wishes,
Radoslav
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
Grid
Asked by
Mark Perry
Top achievements
Rank 1
Answers by
Radoslav
Telerik team
Mark Perry
Top achievements
Rank 1
Share this question
or