Localize Radzen Datagrid Advanced Filter

Hi everyone,

I would like to change the language in the advanced filters of a Datagrid,

Can I just set a language property, or do I need to copy the code of the filter and use it in a filterTemplate?

thanks a lot

Hi @Pierre_Chambon,

There are properties which you can set (all ending with Text) that allow you to customize the messages:

<RadzenDataGrid EqualsText="Is equal to" ContainsText="Contains" 
  DoesNotContainText=".." StartsWithText=".." EndsWithText=".."
  NotEqualsText=".." LessThanText=".." LessThanOrEqualsText=".."
  GreaterThanText=".." GreaterThanOrEqualsText=".."
  IsNullText=".." IsNotNullText=".." ApplyFilterText=".."
  ClearFilterText=".."
/>
1 Like

Is it possible to create a wrapper/template for the datagrid to avoid repeating all those properties in each datagrid?
Thanks

Yes, it’s possible. Just define the DataGrid with desired settings in a razor component and reuse it where needed.

I have just pushed a new feature that should make things easier once released.

Program.cs

using Radzen;
using Radzen.Blazor;

var builder = WebApplication.CreateBuilder(args);

var activator = new RadzenComponentActivator();

// Override any RadzenDataGrid with MyDataGrid which has some property defaults set.
activator.Override(typeof(RadzenDataGrid<>), typeof(MyDataGrid<>));

builder.Services.AddSingleton<IComponentActivator>(activator);

MyDataGrid.cs

class MyDataGrid<T> : Radzen.Blazor.RadzenDataGrid<T>
{
    public MyDataGrid()
    {
        EqualsText = "Is equal to";
    }
}

What happens under the hood is that all instances of <RadzenDataGrid ...> are now MyDataGrid thus having the property values set in the constructor.

2 Likes

This is exactly what I was looking for :slight_smile:

I ended up trying to override the RadzenDataGrid,

public class CustomRadzenDataGrid<T> : RadzenDataGrid<T>
{
    [Parameter] public IStringLocalizer<App>? Loc { get; set; }
    public CustomRadzenDataGrid() : base()
    {
        base.AllowSorting = true;
        base.AllowFiltering = true;
        base.FilterCaseSensitivity = FilterCaseSensitivity.CaseInsensitive;
        base.Style = "max-height: 90vh; margin-bottom: 2vh;";
    }
    protected override void OnParametersSet()
    {
        base.OnParametersSet();
        if (Loc == null) return;
        
        base.AndOperatorText= Loc["And"];
        base.OrOperatorText= Loc["Or"];
        //...
        base.FilterText= Loc["Filter"];
    }
}

Which seems to be working, although I haven't tested it much.
Anyway I'll switch to your activator class when it's available, for sure.

Thanks for the great components and the awesome feedback! :smiley: