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

How to set CurrentFilterFunction="Contains" ShowFilterIcon="false" in columns when databinding with NeedDataSource

1 Answer 255 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Sampath
Top achievements
Rank 1
Sampath asked on 27 May 2015, 02:58 AM

Hi,

I was following the example given about binding data to a radgrid using the needdatasource (Click here to view demo).

Here is my html code, 

<telerik:RadGridID="RadGrid1"runat="server"OnNeedDataSource="RadGrid1_NeedDataSource"AllowSorting="True"AllowPaging="True"ShowGroupPanel="True"GroupingSettings-CaseSensitive="false"AllowFilteringByColumn="True"CellSpacing="-1"GridLines="Both"Skin="Metro"CssClass="rad_header_style"Width="100%">
</telerik:RadGrid>

 

Here is how I bound my data from code behind, 

using System;
using System.Data;
using System.Linq;
using Telerik.Web.UI;
  
publicpartialclasstime_and_action_ganttchart_details : System.Web.UI.Page
{
    protectedvoidPage_Load(objectsender, EventArgs e)
    {
  
    }
  
    protectedvoidRadGrid1_NeedDataSource(objectsender, GridNeedDataSourceEventArgs e)
    {
        shorttechpackID = 93; // short.Parse(Request.QueryString[0]);
  
        DataTable dt = newDataTable();
  
        dt.Columns.Add("Customer", typeof(string));
        dt.Columns.Add("Account", typeof(string));
        dt.Columns.Add("Season", typeof(string));
        dt.Columns.Add("Program", typeof(string));
        dt.Columns.Add("Tech Pack Name", typeof(string));
        dt.Columns.Add("Design Ref", typeof(string));
        dt.Columns.Add("Stroke", typeof(string));
        dt.Columns.Add("Type", typeof(string));
        dt.Columns.Add("Assortment Name", typeof(string));
        dt.Columns.Add("Component", typeof(string));
        dt.Columns.Add("RM Description", typeof(string));
        dt.Columns.Add("Supplier", typeof(string));
        dt.Columns.Add("CSP", typeof(string));
        dt.Columns.Add("Mode", typeof(string));
        dt.Columns.Add("RM Color Code", typeof(string));
        dt.Columns.Add("RM Color Name", typeof(string));
        dt.Columns.Add("Silhoutte", typeof(string));
        dt.Columns.Add("Garment Number", typeof(string));
  
        using(PDLC.Data.PDLCEntities context = newPDLC.Data.PDLCEntities())
        {
            var version = context.V_TimeAndAction_TechPackLeadTime.Where(x => x.TP_ID == techpackID).Select(s => new{ s.VersionID }).Max(p => p.VersionID);
  
            var distinctEvents = context.V_TimeAndAction_TechPackLeadTime.Where(x => x.TP_ID == techpackID && x.VersionID == version).Select(s => new{ s.EventText, s.EventOrder }).Distinct().OrderBy(o => o.EventOrder);
  
            foreach(var eventname indistinctEvents)
            {
                dt.Columns.Add(eventname.EventText, typeof(string));
                dt.Columns.Add("Actual "+ eventname.EventText, typeof(string));
                dt.Columns.Add("Committed "+ eventname.EventText, typeof(string));
            }
  
            var assortmentIdList = context.V_TimeAndAction_TechPackLeadTime.Where(x => x.TP_ID == techpackID && x.VersionID == version).Select(s => new{ s.AS_ID }).Distinct();
  
            foreach(var assortmentId inassortmentIdList)
            {
                var rawMaterialList = context.V_TimeAndAction_TechPackLeadTime.Where(x => x.TP_ID == techpackID && x.VersionID == version && x.AS_ID == assortmentId.AS_ID).Select(s => new{ s.RawMaterialID }).OrderBy(o => o.RawMaterialID).Distinct();
  
                foreach(var rawmaterial inrawMaterialList)
                {
                    DataRow dr = dt.NewRow();
                    var headerDetails = context.V_TimeAndAction_TechPackLeadTime.Where(x => x.TP_ID == techpackID && x.VersionID == version && x.AS_ID == assortmentId.AS_ID && x.RawMaterialID == rawmaterial.RawMaterialID).Select(s => new
                    {
                        s.Cust_Name,
                        s.Account_Name,
                        s.Season_Name,
                        s.ProgramName,
                        s.Design_Ref,
                        s.Stroke,
                        s.StyleTypeName,
                        s.Component_Name,
                        s.Description60Digit,
                        s.sales_office_name,
                        s.Color_Code,
                        s.Color_Name,
                        s.ShapeName,
                        s.GMT_ID,
                        s.TP_Name,
                        s.Assortment_name
                    }).Distinct().First();
  
                    dr["Customer"] = headerDetails.Cust_Name;
                    dr["Account"] = headerDetails.Account_Name;
                    dr["Season"] = headerDetails.Season_Name;
                    dr["Program"] = headerDetails.ProgramName;
                    dr["Tech Pack Name"] = headerDetails.TP_Name;
                    dr["Design Ref"] = headerDetails.Design_Ref;
                    dr["Stroke"] = headerDetails.Stroke;
                    dr["Type"] = headerDetails.StyleTypeName;
                    dr["Assortment Name"] = headerDetails.Assortment_name;
                    dr["Component"] = headerDetails.Component_Name;
                    dr["RM Description"] = headerDetails.Description60Digit;
                    dr["Supplier"] = headerDetails.sales_office_name;
                    dr["CSP"] = "CSP";
                    dr["Mode"] = "Mode";
                    dr["RM Color Code"] = headerDetails.Color_Code;
                    dr["RM Color Name"] = headerDetails.Color_Name;
                    dr["Silhoutte"] = headerDetails.ShapeName;
                    dr["Garment Number"] = headerDetails.GMT_ID;
  
                    var eventIdList = context.V_TimeAndAction_TechPackLeadTime.Where(x => x.TP_ID == techpackID && x.VersionID == version && x.AS_ID == assortmentId.AS_ID && x.RawMaterialID == rawmaterial.RawMaterialID).Select(s => new{ s.EventID, s.EventOrder, s.EventText }).Distinct().OrderBy(o => o.EventOrder);
  
                    foreach(var eventId ineventIdList)
                    {
                        var timeandactiondates = context.V_TimeAndAction_TechPackLeadTime.Where(x => x.TP_ID == techpackID && x.VersionID == version && x.AS_ID == assortmentId.AS_ID && x.RawMaterialID == rawmaterial.RawMaterialID && x.EventID == eventId.EventID).Select(s => new{ s.TimeAndActionES, s.ActualDate, s.CommittedDate }).Distinct().FirstOrDefault();
                        DateTime timeandactiones = (DateTime)timeandactiondates.TimeAndActionES;
                        dr[eventId.EventText] = timeandactiones.ToShortDateString();
                        if(timeandactiondates.ActualDate != null)
                        {
                            DateTime timeandactionactual = (DateTime)timeandactiondates.ActualDate;
                            dr["Actual "+ eventId.EventText] = timeandactionactual.ToShortDateString();
                        }
                        else
                        {
                            dr["Actual "+ eventId.EventText] = timeandactiondates.ActualDate;
                        }
                        if(timeandactiondates.CommittedDate != null)
                        {
                            DateTime timeandactualcommitted = (DateTime)timeandactiondates.CommittedDate;
                            dr["Committed "+ eventId.EventText] = timeandactualcommitted.ToShortDateString();
                        }
                        else
                        {
                            dr["Committed "+ eventId.EventText] = timeandactiondates.CommittedDate;
                        }
                    }
                    dt.Rows.Add(dr);                   
                }
            }
        }
        RadGrid1.DataSource = dt;       
    }
}

Now I want to hide the filter icon and set the column search filter criteria to contains  (CurrentFilterFunction="Contains" ShowFilterIcon="false") in each column. 

Hoping to hear from you soon. Thank you.

 

1 Answer, 1 is accepted

Sort by
0
Maria Ilieva
Telerik team
answered on 01 Jun 2015, 08:17 AM
Hi Sampath,

I would suggest you to review the help topic below that demonstrates setting filter function in code behind. You can apply the same for the columns you need:
http://www.telerik.com/help/aspnet-ajax/grid-applying-default-filter-on-initial-load.html

I hope this helps.

Regards,
Maria Ilieva
Telerik
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 Feedback Portal and vote to affect the priority of the items
Tags
Grid
Asked by
Sampath
Top achievements
Rank 1
Answers by
Maria Ilieva
Telerik team
Share this question
or