Sorting radgrid when filtered using external radfilter

2 posts, 0 answers
  1. adam
    adam avatar
    15 posts
    Member since:
    Sep 2010

    Posted 21 Oct 2010 Link to this post

    i have a radgrid which is populated using the needdatasource, i then have a radfilter set to visible="false". i then have a textbox and two dropdowns that i use to filter the results in the radgrid.

    all this works fine.

    problem - One of the columns "Catagories" which has datafield="NodeParentId", if the results are filtered down and you just have say two records and they are both in the same cagagory, if you sort that column then it returns no records!

    Does anyone have any ideas?

    Heres my code

    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="Search.ascx.cs" Inherits="Controls_Search" %>
    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
    <telerik:RadCodeBlock ID="code" runat="server">
    <script type="text/javascript">
     function comboLoad(sender, eventArgs) {
            sender.set_text(sender.get_items().getItem(0).get_value());
        }
     
        function StopPropagation(e) {
            if (!e) {
                e = window.event;
            }
     
            e.cancelBubble = true;
        }
     
        function nodeClicking(sender, args) {
            var comboBox = $find("<%= CategoryFilter.ClientID %>");
            var nodeValue = document.getElementById("<%= NodeValue.ClientID %>");
             
            var node = args.get_node()
            comboBox.set_text(node.get_text());       
            nodeValue.value = node.get_value();
     
            comboBox.trackChanges();
            comboBox.get_items().getItem(0).set_value(node.get_text());
            comboBox.commitChanges();
     
            comboBox.hideDropDown();
        }
     
        function FindNode() {
            var comboBox = $find("<%= CategoryFilter.ClientID %>");
            var treevw = comboBox.get_items().getItem(0).findControl("RadTree");
            var node = treevw.findNodeByValue(SelectedValue.value);
            node.select()
     
            comboBox.set_text(node.get_text());
     
            comboBox.trackChanges();
            comboBox.get_items().getItem(0).set_value(node.get_text());
            comboBox.commitChanges();
        }
       
    </script>
    </telerik:RadCodeBlock>
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" >
        <AjaxSettings>              
            <telerik:AjaxSetting AjaxControlID="QuickSearchBox">
                <UpdatedControls>                   
                    <telerik:AjaxUpdatedControl ControlID="SearchGrid" LoadingPanelID="RadAjaxLoadingPanel1"></telerik:AjaxUpdatedControl>
                </UpdatedControls>
            </telerik:AjaxSetting>
            <telerik:AjaxSetting AjaxControlID="SearchGrid">
                <UpdatedControls>                   
                    <telerik:AjaxUpdatedControl ControlID="SearchGrid" LoadingPanelID="RadAjaxLoadingPanel1"></telerik:AjaxUpdatedControl>
                </UpdatedControls>
            </telerik:AjaxSetting
            <telerik:AjaxSetting AjaxControlID="FilterBtn">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="SearchGrid" LoadingPanelID="RadAjaxLoadingPanel1"></telerik:AjaxUpdatedControl>
                </UpdatedControls>
            </telerik:AjaxSetting>
            <telerik:AjaxSetting AjaxControlID="TypeFilter">
                <UpdatedControls>                   
                    <telerik:AjaxUpdatedControl ControlID="SearchGrid" LoadingPanelID="RadAjaxLoadingPanel1"></telerik:AjaxUpdatedControl>
                </UpdatedControls>
            </telerik:AjaxSetting>
            <telerik:AjaxSetting AjaxControlID="CategoryFilter">
                <UpdatedControls>                   
                    <telerik:AjaxUpdatedControl ControlID="SearchGrid" LoadingPanelID="RadAjaxLoadingPanel1"></telerik:AjaxUpdatedControl>
                </UpdatedControls>
            </telerik:AjaxSetting>
            <telerik:AjaxSetting AjaxControlID="ResetBtn">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="SearchGrid" LoadingPanelID="RadAjaxLoadingPanel1"></telerik:AjaxUpdatedControl>
                    <telerik:AjaxUpdatedControl ControlID="QuickSearchBox"></telerik:AjaxUpdatedControl>
                     <telerik:AjaxUpdatedControl ControlID="CategoryFilter"></telerik:AjaxUpdatedControl>
                      <telerik:AjaxUpdatedControl ControlID="TypeFilter"></telerik:AjaxUpdatedControl>
                </UpdatedControls>
            </telerik:AjaxSetting>     
        </AjaxSettings>   
    </telerik:RadAjaxManager>
    <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" Transparency="20" BackColor="#ffffff" runat="server">
        <asp:Image ID="Image1" runat="server" AlternateText="Loading..." BorderWidth="0px" ImageUrl="~/Includes/images/ajax/Loading.gif" />
    </telerik:RadAjaxLoadingPanel>  
    <fieldset
        <asp:Label ID="SearchLabel" runat="server" AssociatedControlID="QuickSearchBox">Search Critical Care</asp:Label><br />
        <telerik:RadTextBox ID="QuickSearchBox"  runat="server"></telerik:RadTextBox><br />     
        <telerik:RadComboBox ID="TypeFilter" runat="server" OnSelectedIndexChanged="TypeFilter_SelectedIndexChanged" ></telerik:RadComboBox>
        <telerik:RadComboBox ID="CategoryFilter" runat="server"  OnClientLoad="FindNode" OnSelectedIndexChanged="CategoryFilter_SelectedIndexChanged">
        <ItemTemplate>
            <div onclick="StopPropagation(event)">
                <telerik:RadTreeView ID="CategoryTreeView" runat="server" CheckBoxes="false"  DataFieldID="NodeID" DataFieldParentID="NodeParentID" DataTextField="CategoriesName" DataValueField="NodeID" OnClientNodeClicking="nodeClicking"></telerik:RadTreeView>
            </div>
        </ItemTemplate>
        <Items>
            <telerik:RadComboBoxItem Text=""/>
        </Items>
        </telerik:RadComboBox>
        <input id="NodeValue" value="" runat="server" enableviewstate="true" type="hidden" /><br />
        <asp:Button ID="FilterBtn" OnClick="Filter_Click" runat="server" Text="Filter" />
        <asp:Button ID="ResetBtn" OnClick="Reset_Click" runat="server" Text="Reset" />
        <telerik:RadFilter ID="SearchRadFilter" runat="server" Visible="false" ShowApplyButton="true" ExpressionPreviewPosition="None" ShowLineImages="true" FilterContainerID="SearchGrid"></telerik:RadFilter>
    </fieldset>
        <br />
        <br />
    <telerik:RadGrid ID="SearchGrid" runat="server" MasterTableView-ViewStateMode="Enabled" OnNeedDataSource="SearchGrid_NeedDataSource" OnItemDataBound="SearchGrid_ItemDataBound" OnItemCommand="SearchGrid_ItemCommand" AllowSorting="true" AllowPaging="true" PageSize="5">
        <GroupingSettings CaseSensitive="false"/>
        <MasterTableView AutoGenerateColumns="false">   
        <Columns>
            <telerik:GridTemplateColumn HeaderText="Title" HeaderButtonType="TextButton" DataField="Title" SortExpression="Title" UniqueName="ArticleTitle" AutoPostBackOnFilter="true">
                <ItemTemplate>
                    <asp:Label ID="TitleLabel" Text='<%# Eval("Title") %>' runat="server"></asp:Label>
                </ItemTemplate>
            </telerik:GridTemplateColumn>
            <telerik:GridTemplateColumn HeaderText="Date" HeaderButtonType="TextButton" DataField="Date" SortExpression="Date" UniqueName="ArticleDate" AutoPostBackOnFilter="true">
                <ItemTemplate>
                    <asp:Label ID="DateLabel"  Text='<%# String.Format("{0:dd MM yyyy}",Eval("Date")) %>' runat="server"></asp:Label>
                </ItemTemplate>
            </telerik:GridTemplateColumn>
            <telerik:GridTemplateColumn HeaderText="Synopsis" HeaderButtonType="TextButton" DataField="Synopsis" SortExpression="Synopsis" UniqueName="ArticleSynopsis" AutoPostBackOnFilter="true">
                <ItemTemplate>
                    <asp:Label ID="SynopsisLabel"  Text='<%# Eval("Synopsis") %>' runat="server"></asp:Label>
                </ItemTemplate>
            </telerik:GridTemplateColumn>
            <telerik:GridTemplateColumn HeaderText="Author"  HeaderButtonType="TextButton" DataField="Author" SortExpression="Author" UniqueName="ArticleAuthor" AutoPostBackOnFilter="true">
                <ItemTemplate>
                    <asp:Label ID="AuthorLabel" Text='<%# Eval("Author") %>' runat="server"></asp:Label>
                </ItemTemplate>
            </telerik:GridTemplateColumn>
              <telerik:GridTemplateColumn HeaderText="Category" HeaderButtonType="TextButton" DataField="NodeParentID" SortExpression="NodeParentID" UniqueName="ArticleCategory">
                <ItemTemplate>
                    <asp:Label ID="CategoryLabel"  Text='<%# Eval("NodeParentID") %>' runat="server"></asp:Label>
                </ItemTemplate>
            </telerik:GridTemplateColumn>
            <telerik:GridTemplateColumn HeaderText="Link" HeaderButtonType="TextButton" DataField="Link" SortExpression="Link" UniqueName="ArticleTitle" AutoPostBackOnFilter="true">
                <ItemTemplate>
                    <asp:HyperLink ID="ArticleLink" NavigateUrl='<%# Functions.GetUrl(DataBinder.Eval(Container, "DataItem.NodeAliasPath")) %>' runat="server">Read</asp:HyperLink>
                </ItemTemplate>
            </telerik:GridTemplateColumn>
            <telerik:GridTemplateColumn  Visible="false" HeaderText="Text" HeaderButtonType="TextButton" DataField="Text" SortExpression="Text" UniqueName="ArticleText" AutoPostBackOnFilter="true">
               <ItemTemplate>
                    <asp:Label ID="TextLabel" Text='<%# Eval("Text") %>' runat="server"></asp:Label>
                </ItemTemplate>
            </telerik:GridTemplateColumn>        
            <telerik:GridTemplateColumn Visible="false" HeaderText="ClassDisplayName" HeaderButtonType="TextButton" DataField="ClassDisplayName" SortExpression="ClassDisplayName" UniqueName="ArticleClassName" AutoPostBackOnFilter="true">
               <ItemTemplate>
                    <asp:Label ID="ClassDisplayName" Text='<%# Eval("ClassDisplayName") %>' runat="server"></asp:Label>
                </ItemTemplate>
            </telerik:GridTemplateColumn>      
        </Columns>
        </MasterTableView>   
    </telerik:RadGrid>


    and c#

    using System;
    using System.Data;
    using System.Collections.Generic;
    using System.Linq;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
     
    using CMS.CMSHelper;
    using CMS.GlobalHelper;
    using CMS.ISearchEngine;
    using Telerik.Web.UI;
     
     
    public partial class Controls_Search : System.Web.UI.UserControl
    {
        
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadItemGroups();
                LoadDocTypes();
            }
        }
     
        void LoadItemGroups()
        {
            DataSet ds = TreeHelper.SelectNodes("/%", false, "CriticalCare.Categories", null, "NodeOrder");
     
            if (!DataHelper.DataSourceIsEmpty(ds))
            {
                RadTreeView catagoryTreeview = (RadTreeView)this.CategoryFilter.Items[0].FindControl("CategoryTreeView");
                 
                int x = 0;
     
                foreach (DataRow row in ds.Tables[0].Rows)
                {
                    if (ds.Tables[0].Rows[x].ItemArray.GetValue(9).ToString() == "1")
                    {
                        row[9] = DBNull.Value;
                    }
                    x++;
                }
     
                catagoryTreeview.DataSource = ds;
                catagoryTreeview.MaxDataBindDepth = 2;
                catagoryTreeview.DataBind();
                catagoryTreeview.ExpandAllNodes();      
                 
            }
       }
     
        void LoadDocTypes()
        {
            DataSet ds = TreeHelper.SelectNodes("/%", false, "CriticalCare.Conclusion;CriticalCare.Literature;CriticalCare.Theory;CriticalCare.ClinicalApps;CriticalCare.CaseStudies;CriticalCare.Downloads;CriticalCare.Video", null, "ClassDisplayName Asc", -1, true);
     
            if (!DataHelper.DataSourceIsEmpty(ds))
            {
                DataTable dt = new DataTable();
                for (int i = 0; i < ds.Tables.Count; i++)
                {
                    dt.Merge(ds.Tables[i]);
                }
     
                IEnumerable<DataRow> types = (from row in dt.AsEnumerable()
                                                       group row by row.Field<string>("ClassDisplayName") into g
                                                       select g.FirstOrDefault());
     
                DataTable dtType = types.CopyToDataTable();
     
                TypeFilter.DataSource = dtType;
                TypeFilter.DataTextField = "ClassDisplayName";
                TypeFilter.DataValueField = "ClassDisplayName";
                TypeFilter.DataBind();
     
                TypeFilter.Items.Insert(0, new RadComboBoxItem("Filter by article type"));
            }
        }
     
        protected void SearchGrid_ItemCommand(object sender, GridCommandEventArgs e)
        {
            if (e.CommandName == RadGrid.SortCommandName)
            {
     
                SearchGrid.Rebind();
                SearchRadFilter.FireApplyCommand();
            }
        }
     
        protected void SearchGrid_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
        {
            DataSet ds = TreeHelper.SelectNodes("/%", false, "CriticalCare.Conclusion;CriticalCare.Literature;CriticalCare.Theory;CriticalCare.ClinicalApps;CriticalCare.CaseStudies;CriticalCare.Downloads;CriticalCare.Video", null, "Date Asc", -1, true);
     
            if (!DataHelper.DataSourceIsEmpty(ds))
            {
                DataTable dt = new DataTable();
     
                for (int i = 0; i < ds.Tables.Count; i++)
                {
                    dt.Merge(ds.Tables[i]);
                }
     
                dt.DefaultView.Sort = "Date Desc";
                SearchGrid.DataSource = dt;
                
            }
            else
            {
                SearchGrid.Visible = false;
            }      
        }
     
        protected void SearchGrid_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
        {
            if (e.Item is GridDataItem)
            {
                DataRowView dr = (DataRowView)e.Item.DataItem;
     
                GridDataItem item = (GridDataItem)e.Item;
                Label Category = item.FindControl("CategoryLabel") as Label;
                int parentid = Convert.ToInt32(dr["NodeParentID"].ToString());
                int docid = TreeHelper.SelectSingleNode(parentid).DocumentID;
                CMS.TreeEngine.TreeNode node = TreeHelper.SelectSingleDocument(docid);
                string documentname = node.DocumentName.ToString();
                Category.Text = documentname;
            }
        }
     
        protected void Filter_Click(object sender, EventArgs e)
        {
            SearchRadFilter.RootGroup.Expressions.Clear();    
     
     
            if (QuickSearchBox.Text != "")
            {
                RadFilterGroupExpression textbox = new RadFilterGroupExpression();
                textbox.GroupOperation = RadFilterGroupOperation.Or;
                RadFilterContainsFilterExpression expression1 = new RadFilterContainsFilterExpression("Synopsis");
                RadFilterContainsFilterExpression expression2 = new RadFilterContainsFilterExpression("Title");
                RadFilterContainsFilterExpression expression3 = new RadFilterContainsFilterExpression("Text");
                expression1.Value = QuickSearchBox.Text;
                expression2.Value = QuickSearchBox.Text;
                expression3.Value = QuickSearchBox.Text;
                SearchRadFilter.RootGroup.AddExpression(textbox);
                textbox.AddExpression(expression1);
                textbox.AddExpression(expression2);
                textbox.AddExpression(expression3);
            }
     
            if (TypeFilter.SelectedIndex != 0)
            {
                RadFilterGroupExpression type = new RadFilterGroupExpression();
                RadFilterContainsFilterExpression expr = new RadFilterContainsFilterExpression("ClassDisplayName");
                expr.Value = TypeFilter.SelectedValue;
                SearchRadFilter.RootGroup.AddExpression(type);
                type.AddExpression(expr);
            }
     
            if (NodeValue.Value != "")
            {
                RadFilterGroupExpression category = new RadFilterGroupExpression();
                RadFilterContainsFilterExpression expr2 = new RadFilterContainsFilterExpression("NodeParentID");
                expr2.Value = NodeValue.Value;
                SearchRadFilter.RootGroup.AddExpression(category);
                category.AddExpression(expr2);
            }
             
            SearchRadFilter.FireApplyCommand();     
        }
     
        protected void TypeFilter_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e)
        {
            
            
            SearchRadFilter.FireApplyCommand();
        }
     
        protected void CategoryFilter_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e)
        {
             
            SearchRadFilter.FireApplyCommand();
        }
     
        protected void Reset_Click(object sender, EventArgs e)
        {
             
            SearchRadFilter.RootGroup.Expressions.Clear();
            QuickSearchBox.Text = "";
            TypeFilter.SelectedIndex = 0;
            NodeValue.Value = "";
            SearchRadFilter.FireApplyCommand();
            
        }
    }
  2. Daniel
    Admin
    Daniel avatar
    4946 posts

    Posted 28 Oct 2010 Link to this post

    Hello Adam,

    Unfortunately it is not easy to determine what causes the problem based on the provided information. Can you please try to isolate the issue in a simple runnable project? This way we will be able to debug it locally and then provide straight-to-the-point answer.

    Regards,
    Daniel
    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
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top