From e5e36040f6d06f4defac2ebb1ed333b562da7b17 Mon Sep 17 00:00:00 2001 From: Vikram Reddy Date: Sat, 5 Aug 2023 19:21:18 +0530 Subject: [PATCH] Grid: Translation of the filtering of the grid #292 - draft --- .../Grid/Grid_Demo_30_Translations.razor | 28 +++++++++++++++- blazorbootstrap/Components/Grid/Grid.razor | 2 +- blazorbootstrap/Components/Grid/Grid.razor.cs | 32 +++++++++++-------- .../Components/Grid/GridColumnFilter.razor | 1 + .../Components/Grid/GridColumnFilter.razor.cs | 4 ++- .../Models/GridFiltersTranslationDelegate.cs | 6 ++++ 6 files changed, 57 insertions(+), 16 deletions(-) create mode 100644 blazorbootstrap/Models/GridFiltersTranslationDelegate.cs diff --git a/BlazorBootstrap.Demo/Pages/Grid/Grid_Demo_30_Translations.razor b/BlazorBootstrap.Demo/Pages/Grid/Grid_Demo_30_Translations.razor index 17f42e819..48935129c 100644 --- a/BlazorBootstrap.Demo/Pages/Grid/Grid_Demo_30_Translations.razor +++ b/BlazorBootstrap.Demo/Pages/Grid/Grid_Demo_30_Translations.razor @@ -1,7 +1,8 @@  employees = default!; + private async Task> GridFiltersTranslationProvider() + { + var filtersTranslation = new HashSet(); + + // number/date/boolean + filtersTranslation.Add(new("=", "Equals", FilterOperator.Equals)); + filtersTranslation.Add(new("!=", "Not equals", FilterOperator.NotEquals)); + // number/date + filtersTranslation.Add(new("<", "Less than", FilterOperator.LessThan)); + filtersTranslation.Add(new("<=", "Less than or equals", FilterOperator.LessThanOrEquals)); + filtersTranslation.Add(new(">", "Greater than", FilterOperator.GreaterThan)); + filtersTranslation.Add(new(">=", "Greater than or equals", FilterOperator.GreaterThanOrEquals)); + // string + filtersTranslation.Add(new("*a*", "Contains", FilterOperator.Contains)); + filtersTranslation.Add(new("a**", "Starts with", FilterOperator.StartsWith)); + filtersTranslation.Add(new("**a", "Ends with", FilterOperator.EndsWith)); + filtersTranslation.Add(new("=", "Equals", FilterOperator.Equals)); + // common + filtersTranslation.Add(new("x", "Clear", FilterOperator.Equals)); + + return await Task.FromResult(filtersTranslation); + } + private async Task> EmployeesDataProvider(GridDataProviderRequest request) { if (employees is null) // pull employees only one time for client-side filtering, sorting, and paging @@ -56,4 +80,6 @@ new Employee1 { Id = 111, Name = "Glenda", Designation = "Data Engineer", DOJ = new DateOnly(1994, 1, 12), IsActive = true }, }; } + + } \ No newline at end of file diff --git a/blazorbootstrap/Components/Grid/Grid.razor b/blazorbootstrap/Components/Grid/Grid.razor index c0f0b3d6e..85ea83725 100644 --- a/blazorbootstrap/Components/Grid/Grid.razor +++ b/blazorbootstrap/Components/Grid/Grid.razor @@ -33,7 +33,7 @@ @if (column.Filterable) { - + /// This event is triggered when the user clicks on the row. + /// Set AllowRowClick to true to enable row clicking. + /// + [Parameter] public EventCallback> OnRowClick { get; set; } + + /// + /// This event is triggered when the user double clicks on the row. + /// Set AllowRowClick to true to enable row double clicking. + /// + [Parameter] public EventCallback> OnRowDoubleClick { get; set; } + /// /// Gets or sets the page size of the grid. /// @@ -676,18 +690,6 @@ private string GetPaginationItemsText() /// [Parameter] public bool Responsive { get; set; } - /// - /// This event is triggered when the user clicks on the row. - /// Set AllowRowClick to true to enable row clicking. - /// - [Parameter] public EventCallback> OnRowClick { get; set; } - - /// - /// This event is triggered when the user double clicks on the row. - /// Set AllowRowClick to true to enable row double clicking. - /// - [Parameter] public EventCallback> OnRowDoubleClick { get; set; } - /// /// This event is fired when the item selection changes. /// @@ -704,7 +706,11 @@ private string GetPaginationItemsText() /// [Parameter] public GridSettingsProviderDelegate SettingsProvider { get; set; } = default!; - [Parameter, EditorRequired] public string ItemsPerPageText { get; set; } = "Items per page"; + /// + /// Filters transalation is for grid filters to render. + /// The provider should always return a 'FilterOperatorInfo' collection, and 'null' is not allowed. + /// + [Parameter] public GridFiltersTranslationDelegate FiltersTranslationProvider { get; set; } = default!; #endregion Properties } diff --git a/blazorbootstrap/Components/Grid/GridColumnFilter.razor b/blazorbootstrap/Components/Grid/GridColumnFilter.razor index f5f55f209..14b6ea1cb 100644 --- a/blazorbootstrap/Components/Grid/GridColumnFilter.razor +++ b/blazorbootstrap/Components/Grid/GridColumnFilter.razor @@ -1,5 +1,6 @@ @namespace BlazorBootstrap @inherits BaseComponent +@typeparam TItem