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

RadGrid FilterType Header Context - No accepting List Box Filters

1 Answer 41 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Andy
Top achievements
Rank 1
Andy asked on 29 Mar 2017, 05:54 PM

I am having the following problem.  I am doing the excel type Filter (FilterType="HederContext").  All the filtering options work except for the list box combo.  I am retrieving the list box options (and they display), but when I check to filter one of them it does not filter any of the data elements.  I can use the sort ascending/descending/add & remove columns.  Start by and equals.  

I just cannot use any fields in the combo box.

Here is the code sample:

 

<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPages/WebForms.master" AutoEventWireup="true" CodeBehind="PostageReport.aspx.cs" Inherits="Site.Areas.Reports.PostageReport.PostageReport" %>
 
<asp:Content ID="Content7" ContentPlaceHolderID="ContentBottom" runat="server">
    Date From:
    <asp:Label runat="server" Visible="true" ID="lblDf"></asp:Label><br />
    Date To:
    <asp:Label runat="server" Visible="true" ID="lblDt"></asp:Label>
 
<%--    <telerik:RadScriptManager ID ="RadScriptManager1" runat="server" />--%>
    <telerik:RadSkinManager ID="RadSkinManager1" runat="server" ShowChooser="true" />
    <telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server" EnableAJAX="true" LoadingPanelID="LoadingPanel1">
        <telerik:RadGrid ID="RadGrid1" runat="server" RenderMode="Lightweight"
            AllowFilteringByColumn="true"
            FilterType="HeaderContext"
            EnableHeaderContextMenu="true"
            EnableHeaderContextFilterMenu="true"
            EnableFiltering="true"
            AllowPaging="True"
            PagerStyle-AlwaysVisible="true"
            AllowSorting="true"
            GroupingEnabled="true"
            OnNeedDataSource="RadGrid1_NeedDataSource" 
            OnFilterChecklistItemsRequested="RadGrid1_FilterCheckListItemsRequested">
            <MasterTableView AutoGenerateColumns="false" DataKeyNames="new_entrynumber" AllowFilteringByColumn="true" AllowSorting="true" OverrideDataSourceControlSorting="true">
                <Columns>
                    <telerik:GridBoundColumn FilterCheckListEnableLoadOnDemand="true" DataField="new_entrydate" DataFormatString="{0:d}" FilterControlWidth="45px" DataType="System.DateTime" HeaderText="Date" UniqueName="Date"></telerik:GridBoundColumn>
                  
                    <telerik:GridBoundColumn FilterCheckListEnableLoadOnDemand="true" DataField="new_customernumberid" FilterControlWidth="45px" DataType="System.String" HeaderText="Account Number" UniqueName="CustomerNumber"></telerik:GridBoundColumn>
                    <telerik:GridBoundColumn FilterCheckListEnableLoadOnDemand="true" DataField="new_costcenter" FilterControlWidth="45px" DataType="System.String" HeaderText="Cost Center" UniqueName="CostCenter"></telerik:GridBoundColumn>
                    <telerik:GridBoundColumn FilterCheckListEnableLoadOnDemand="true" DataField="new_installname" FilterControlWidth="45px" DataType="System.String" HeaderText="Customer Name" UniqueName="CustomerName"></telerik:GridBoundColumn>
                  
                    <telerik:GridBoundColumn FilterCheckListEnableLoadOnDemand="true" DataField="new_installcity" FilterControlWidth="45px" DataType="System.String" HeaderText="City" UniqueName="City"></telerik:GridBoundColumn>
                    <telerik:GridBoundColumn FilterCheckListEnableLoadOnDemand="true" DataField="new_installstate" FilterControlWidth="30px" DataType="System.String" HeaderText="State" UniqueName="State"></telerik:GridBoundColumn>
                     
                    <telerik:GridBoundColumn FilterCheckListEnableLoadOnDemand="true" DataField="new_serialnumber" FilterControlWidth="45px" DataType="System.String" HeaderText="Serial Number" UniqueName="SerialNumber"></telerik:GridBoundColumn>
                    <telerik:GridBoundColumn FilterCheckListEnableLoadOnDemand="true" DataField="new_entrydescription" FilterControlWidth="45px" DataType="System.String" HeaderText="Description" UniqueName="TransDescription"></telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="new_entryamount"  DataFormatString="{0:N}" FilterControlWidth="45px" HeaderText="Amount" UniqueName="TransAmount">
                        <ItemStyle HorizontalAlign="Right" />
                        <HeaderStyle HorizontalAlign="Right" />
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="new_numberimprints"  FilterControlWidth="45px" DataType="System.Decimal" HeaderText="Total Piece Count" UniqueName="TotalPieceCount">
                        <ItemStyle HorizontalAlign="Right" />
                        <HeaderStyle HorizontalAlign="Right" />
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="new_postageused" DataFormatString="{0:N}"  FilterControlWidth="45px" DataType="System.Decimal" HeaderText="Total Postage Used" UniqueName="TotalPostageUsed">
                        <ItemStyle HorizontalAlign="Right" />
                        <HeaderStyle HorizontalAlign="Right" />
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="new_endingcredit" DataFormatString="{0:N}"  FilterControlWidth="45px" DataType="System.Decimal" HeaderText="Ending Credit" UniqueName="EndingCredit">
                        <ItemStyle HorizontalAlign="Right" />
                        <HeaderStyle HorizontalAlign="Right" />
                    </telerik:GridBoundColumn>
                </Columns>
            </MasterTableView>
        </telerik:RadGrid>
    </telerik:RadAjaxPanel>
 
    <%--<CommandItemSettings ShowAddNewRecordButton="False" ShowExportToCsvButton="True" ShowExportToExcelButton="True" ShowExportToPdfButton="True" ShowExportToWordButton="True" />--%>
</asp:Content>
<asp:Content ID="Content8" ContentPlaceHolderID="Scripts" runat="server">
</asp:Content>

 

C# code behind it:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Site.Pages;
using Telerik.Web.UI;
using Xrm;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Query;
using System.Data;
using System.Globalization;
using System.Threading;
 
 
namespace Site.Areas.Reports.PostageReport
{
    public partial class PostageReport : PortalPage
    {
        private DateTime df;
        private DateTime dt;
        private string _guid;
 
        public void Button2_Click(object sender, ImageClickEventArgs e)
        {
            // TODO: Implement this method
            throw new NotImplementedException();
        }
 
        public void RadGrid1_SortCommand(object sender, GridSortCommandEventArgs e)
        {
            // TODO: Implement this method
            throw new NotImplementedException();
        }
 
        protected void Page_Load(object sender, EventArgs e)
        {
            RedirectToLoginIfAnonymous();
        }
 
        protected void RadGrid1_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
        {
            (sender as RadGrid).DataSource = GetDataTable();
        }
 
        protected void RadGrid1_FilterCheckListItemsRequested(object sender, GridFilterCheckListItemsRequestedEventArgs e)
        {
            string DataField = (e.Column as IGridDataColumn).GetActiveDataField();
 
            e.ListBox.DataSource = GetDistinctColumn(DataField);
            e.ListBox.DataKeyField = DataField;
            e.ListBox.DataTextField = DataField;
            e.ListBox.DataValueField = DataField;
            e.ListBox.DataBind();
        }
 
        public void ParseParameters()
        {
            if (Request.QueryString["df"] != null) {
                df = Convert.ToDateTime(Request.QueryString["df"]).AddDays(1).AddDays(-1);
            } else {
                // Default is from date two years back
                df = DateTime.Today.AddDays(-730);
            }
 
            if (Request.QueryString["dt"] != null) {
                dt = Convert.ToDateTime(Request.QueryString["dt"]).AddDays(1).AddTicks(-1);
            } else {
                df = DateTime.Today;
            }
 
             
            if (Request.QueryString["id"] != null) {
                _guid = Request.QueryString["id"];
            }else {
                _guid = "all";
            }
        }
 
 
        public DataTable GetDistinctColumn(string columnName)
        {
            DataTable dTable = new DataTable();
            var xrm = new Xrm.XrmServiceContext("Xrm");
 
            ParseParameters();
 
            lblDf.Text = df.ToShortDateString();
            lblDt.Text = dt.ToShortDateString();
 
            Xrm.Account account = new Xrm.Account();
             
            if (_guid == "all")
            {
                account = xrm.Retrieve(Xrm.Account.EntityLogicalName, Contact.ParentCustomerId.Id, new ColumnSet(true)).ToEntity<Xrm.Account>();
 
            }
            else
            {
                Guid _account = new Guid(_guid);
                account = xrm.Retrieve(Xrm.Account.EntityLogicalName, _account, new ColumnSet(true)).ToEntity<Xrm.Account>();
            }
 
            dTable.Columns.Add(columnName);
 
            QueryExpression query = new QueryExpression();
            query.EntityName = "new_tdcdata";
            query.ColumnSet.AddColumn(columnName);
            query.Distinct = true;
 
            query.Criteria = new Microsoft.Xrm.Sdk.Query.FilterExpression();
            if (_guid == "all")
            {
                query.Criteria.AddCondition("new_account",ConditionOperator.Equal,account.Id);
            } else {
                query.Criteria.AddCondition("new_customernumberid",ConditionOperator.Equal,account.Id);
            }
 
            Microsoft.Xrm.Sdk.Query.FilterExpression childFilter = query.Criteria.AddFilter(LogicalOperator.And);
            childFilter.AddCondition("new_entrydate", ConditionOperator.Between, df, dt);
 
            EntityCollection results = xrm.RetrieveMultiple(query);
 
            foreach (var c in results.Entities)
            {
                DataRow row = dTable.NewRow();
                if (columnName == "new_entrydate")
                {
                    row[columnName] = c.GetAttributeValue<DateTime>(columnName).ToString("M/dd/yyyy", CultureInfo.InvariantCulture);
                }
                else
                {
                    if (columnName == "new_customernumberid")
                    {
                        Guid _account = c.GetAttributeValue<Guid>(columnName);
                        account = xrm.Retrieve(Xrm.Account.EntityLogicalName, _account, new ColumnSet(true)).ToEntity<Xrm.Account>();
                        row[columnName] = account.Name;
                    }
                    else
                    {
                        row[columnName] = c.GetAttributeValue<string>(columnName);
 
                    }
                }
                dTable.Rows.Add(row);
            }
                         
            return (dTable);
        }
 
 
        public DataTable GetDataTable()
        {
 
            DataTable dTable = new DataTable();
            var xrm = new Xrm.XrmServiceContext("Xrm");
           
            ParseParameters();
 
            lblDf.Text = df.ToShortDateString();
            lblDt.Text = dt.ToShortDateString();
 
            Xrm.Account account = new Xrm.Account();
 
            if (_guid == "all")
            {
                account = xrm.Retrieve(Xrm.Account.EntityLogicalName, Contact.ParentCustomerId.Id, new ColumnSet(true)).ToEntity<Xrm.Account>();
 
            }
            else
            {
                Guid _account = new Guid(_guid);
                account = xrm.Retrieve(Xrm.Account.EntityLogicalName, _account, new ColumnSet(true)).ToEntity<Xrm.Account>();
            }
             
            RadGrid1.ExportSettings.FileName = string.Format("{0}-{1}-{2}-{3}-{4}",
                                                             "PostageReport",
                                                             account.Name,
                                                             df.ToShortDateString().Replace("/", ""),
                                                             dt.ToShortDateString().Replace("/", ""),
                                                             DateTime.Now.ToString("yyyyMMddHHmmss"));
 
 
            dTable.Columns.Add("new_entrynumber", typeof(Int32));
            dTable.Columns.Add("new_entrydate", typeof(DateTime));
            dTable.Columns.Add("new_account");
            dTable.Columns.Add("new_customernumberid");
            dTable.Columns.Add("new_costcenter");
            dTable.Columns.Add("new_installname");
            dTable.Columns.Add("new_installaddress");
            dTable.Columns.Add("new_installcity");
            dTable.Columns.Add("new_installstate");
            dTable.Columns.Add("new_installzip");
            dTable.Columns.Add("new_serialnumber");
            dTable.Columns.Add("new_entrydescription");
            dTable.Columns.Add("new_entryamount",typeof(decimal));
            dTable.Columns.Add("new_startingcredit", typeof(decimal));
            dTable.Columns.Add("new_startingdebit", typeof(decimal));
            dTable.Columns.Add("new_entrychecknumber");
            dTable.Columns.Add("new_numberimprints",typeof(Int32));
            dTable.Columns.Add("new_postageused", typeof(decimal));
            dTable.Columns.Add("new_endingcredit", typeof(decimal));
            dTable.Columns.Add("new_endingdebit", typeof(decimal));
            //dTable.Columns.Add("Price Group");
 
            IQueryable<new_tdcdata> stmt; //xrm.new_tdcdataSet.Where(t => t.new_Account.Id == account.Id);
            if (_guid == "all")
            {
                stmt = xrm.new_tdcdataSet.Where(t => t.new_Account.Id == account.Id && t.new_entryDate >= df && t.new_entryDate <= dt);
            }
            else
            {
                stmt = xrm.new_tdcdataSet.Where(t => t.new_CustomerNumberId.Id == account.Id && t.new_entryDate >= df && t.new_entryDate <= dt);
            }
 
            Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-US");
            Thread.CurrentThread.CurrentCulture.NumberFormat.CurrencyNegativePattern = 1;
             
            foreach (var s in stmt)
            {
                // List<string> row = new List<string>();
                DataRow row = dTable.NewRow();
                row["new_entrynumber"] = s.new_entryNumber;
                row["new_entrydate"] = s.new_entryDate;
                row["new_account"] = (s.new_Account.Name ?? "");
                row["new_customernumberid"] = (s.new_CustomerNumberId.Name ?? "");
                row["new_costcenter"] = (s.new_CostCenter ?? "");
                row["new_installname"] = (s.new_InstallName ?? "");
                row["new_installaddress"] = (s.new_InstallAddress ?? "");
                row["new_installcity"] =(s.new_InstallCity ?? "");
                row["new_installstate"] = (s.new_InstallState ?? "");
                row["new_installzip"] = (s.new_InstallZip ?? "");
                row["new_serialnumber"] = (s.new_serialNumber ?? "n/a");
                //row.Add(string.Format("{0} {1}", s.new_entryDescription ?? "", s.new_entryDescription2 ?? ""));
                row["new_entrydescription"] = (string.Format("{0}", s.new_entryDescription ?? ""));
                row["new_entryamount"] = s.new_entryAmount;
                row["new_startingcredit"] = s.new_startingCredit;
                row["new_startingdebit"] =  s.new_startingDebit;
                row["new_entrychecknumber" ] = (s.new_entryCheckNumber ?? "--");
                row["new_numberimprints"] = s.new_numberImprints;
                row["new_postageused"] = s.new_postageUsed;
                row["new_endingcredit"] = s.new_endingCredit;
                row["new_endingdebit"] = s.new_endingDebit;
 
                dTable.Rows.Add(row);
            }
 
 
            return (dTable);
 
        }
    }
}

1 Answer, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 30 Mar 2017, 06:42 AM
Hi Andy,

I've already replied to your query in your ticket with ID: 1101024. I suggest that we continue our conversation on the mentioned thread.

Regards,
Eyup
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Grid
Asked by
Andy
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Share this question
or