We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Is it possible to add a placeholder in the filter cell?

I'm using a GridDataControl with FilterBarMode=Immediate. Is it possible to add a "Placehoder" like "Type to filter" or "Type to search" in the filter cell? It would be a grey text that disappears as soon as you start typing there.
I haven't found it in the documentation but I may be searching it wrongly.
Thanks in advance

3 Replies

BR Balamurugan Rajaraman Syncfusion Team August 8, 2017 11:58 AM UTC

Hi Carlos 
 
Thanks for contacting Syncfusion support. 
 
We have checked your query “To add a placeholder in the filter cell”. You can able to achieve your requirement by customizing the OnRender method of the GridDataFilterBarCellRenderer as like the below provide code sample. 
 
 
this.dataGrid.Model.CellModels.Remove("FilterBarCell"); 
this.dataGrid.Model.CellModels.Add("FilterBarCell", new GridFilterBarCellModelExt()); 
 
. . .  
 
public class GridFilterBarCellModelExt : GridCellModel<GridCellTextBoxRendererExt> 
{ 
 
} 
 
public class GridCellTextBoxRendererExt: GridDataFilterBarCellRenderer 
{ 
public GridCellTextBoxRendererExt():base() 
{ 
 
} 
       
protected override void OnRender(DrawingContext dc, RenderCellArgs rca, GridRenderStyleInfo style) 
{ 
    if (rca.CellUIElements != null) 
        return; 
    var margins = style.TextMargins.ToThickness(); 
    if (style.HasImageIndex) 
    { 
        margins = style.AdjustImageWidthAndHeightToMargin(margins, rca.CellRect.Size); 
    } 
    else 
    { 
        margins = style.ErrorInfo.AdjustErrorInfoMargin(margins, rca.CellRect.Size); 
    } 
    Rect textRectangle = rca.SubtractBorderMargins(rca.CellRect, margins); 
    if (textRectangle.IsEmpty) 
        return; 
 
    margins.Left = Math.Max(margins.Left, 2); 
    margins.Right = Math.Max(margins.Right, 2); 
    string text = GetControlText(style); 
    if (text == string.Empty) 
        text = "Type to filter"; 
    GridTextBoxPaint.DrawText(dc, textRectangle, text, style); 
} 
      
} 
 
In this sample we have applied the custom test in the OnRender to display that text as like the placeholder text. We have attached the sample for your reference you can able to get it from below link 
 
 
Regards, 
Balamurugan R 



CF Carlos Fernando Consigli February 12, 2018 11:15 PM UTC

I'm really REALLY sorry about my lack of feedback on this. It was a minor request and it was postponed and almost forgotten.
It worked perfectly, thanks a lot for your help.


MK Muthukumar Kalyanasundaram Syncfusion Team February 13, 2018 01:15 PM UTC

Hi Carlos, 
 
You are welcome. Please let us know if you need further assistance. 
 
Regards, 
Muthukumar K 


Loader.
Live Chat Icon For mobile
Up arrow icon