Filter customization

Hello,

By default I have this filter:



I would like hide the combobox and set the "Contains" option as default filtering type.

My second question: can I place a filter icon into to right side of the filter cell? (instead of dropdown icon for example)

Can you help me please how can I do this?

Thank you!


3 Replies 1 reply marked as answer

VS Vijayarasan Sivanandham Syncfusion Team September 16, 2022 04:59 PM UTC

Hi SZL,

Please find answer for your queries below

Queries

Solutions

 

I would like set the "Contains" option as default filtering type.

 


Your requirement to set the Contains option as the default filtering type in FilterRow of SfDataGrid can be achieved by setting the FilterRowCondition property in GridColum. It can be applied in SfDataGrid in two ways,

1.AutoGenerateColumn as true

            In this case, the SfDataGrid column is generated automatically. So, you can set the FilterRowCondition in

AutoGeneratingColumn event in SfDataGrid. Please refer to the following code snippet,


//Case 1 AutoGenerateColumn as true

sfDataGrid1.AutoGeneratingColumn += OnAutoGeneratingColumn;

 

private void OnAutoGeneratingColumn(object sender, Syncfusion.WinForms.DataGrid.Events.AutoGeneratingColumnArgs e)

{

    if (e.Column is GridTextColumn)

    {

        e.Column.FilterRowEditorType = "TextBoxEditorExt";

        //here define the default FilterRowCondition

        e.Column.FilterRowCondition = FilterRowCondition.Contains;

    }

}

 


2.AutoGenerateColumn as false

         
In this case, SfDataGrid columns are defined manually you can set the FilterRowCondition property in GridColumn. Please refer to the below code snippet,

 

//Case 2 AutoGenerateColumn as False Manually added column header text changed

sfDataGrid1.AutoGenerateColumns = false;

sfDataGrid1.DataSource = table;

 

sfDataGrid1.Columns.Add(new GridTextColumn()

{

    MappingName = "CustomerID",

    HeaderText = "Customer ID",

    FilterRowCondition = FilterRowCondition.Contains,

  FilterRowEditorType = "TextBoxEditorExt"

});

 

 

UG Link: https://help.syncfusion.com/windowsforms/datagrid/filterrow

 

I would like hide the combobox or

can I place a filter icon into to right side of the filter cell? (instead of dropdown icon for example)

 

 

Your requirement to hide the Combobox or place a filter icon on the right side of the filter in SfDataGrid can be achieved by customizing the filter row renderer behavior by overriding the corresponding renderer associated with the filter row cell. Please refer to the following code snippet,

//Add the custom renderer to the FilterRowCellRenderers collection.

sfDataGrid1.FilterRowCellRenderers.Add("TextBoxEditorExt", new FilterRowTextBoxRendererExt(sfDataGrid1));

 

 

public class FilterRowTextBoxRendererExt : FilterRowTextBoxCellRenderer

 {

     public SfDataGrid DataGrid { get; set; }

     public FilterRowTextBoxRendererExt(SfDataGrid dataGrid)

         : base()

     {

         DataGrid = dataGrid;

     }

 

 

     public override void OpenFilterOptionPopup()

     {

         //here skip base operations to handle the click operations of ComboBox in filter cell

     }

 

     //protected override void DrawDropDownButton(Graphics g, Rectangle rect, Color backColor)

     //{

     //    //here skip base operations to hide the Combobox in filter cell

     //}

 

     protected override void DrawDropDownButton(Graphics g, Rectangle rect, Color backColor)

     {

         if (DataGrid.FilterRowPosition == RowPosition.Bottom || DataGrid.FilterRowPosition == RowPosition.FixedTop)

         {

             rect.Height -= 1;

             rect.Y += 1;

         }

 

         g.FillRectangle(new SolidBrush(backColor), rect);

         //here place a filter icon on to right side of the filter cell instead of ComboBox

         Bitmap img = new Bitmap(Image.FromFile(@"..\..\FilterIcon.png"));          

            

         g.DrawImage(img, new Rectangle(rect.Location, rect.Size));

 

     }

 

 }

UG Link: https://help.syncfusion.com/windowsforms/datagrid/filterrow#customizing-filterrow-cellrenderer

In your sample used different columns you need to customization-based the column type. Please refer to the below user documentation for column types based filter row editors,

UG Link: https://help.syncfusion.com/windowsforms/datagrid/filterrow#filterrow-options


Please find the sample in the attachment and let us know if you have any concerns in this.


Regards,

Vijayarasan S


If this post is helpful, please consider Accepting it as the solution so that other members can locate it more quickly.


Attachment: Sample_505dc6a.zip

Marked as answer

SZ SZL replied to Vijayarasan Sivanandham September 17, 2022 04:39 PM UTC

Thank you very much, its works perfectly!



VS Vijayarasan Sivanandham Syncfusion Team September 19, 2022 05:51 AM UTC

Hi SZL,

We are glad to know that the reported problem has been resolved at your end. Please let us know if you have any further queries on this. We are happy to help you😊.

Regards,
Vijayarasan S


Loader.
Up arrow icon