Skip to content

Commit

Permalink
Grid: Translation of the filtering of the grid #292 - draft
Browse files Browse the repository at this point in the history
  • Loading branch information
gvreddy04 committed Aug 5, 2023
1 parent 2e45a12 commit e5e3604
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 16 deletions.
28 changes: 27 additions & 1 deletion BlazorBootstrap.Demo/Pages/Grid/Grid_Demo_30_Translations.razor
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<Grid TItem="Employee1"
AllowPaging="true"
Class="table table-hover table-bordered table-striped"
DataProvider="EmployeesDataProvider"
AllowPaging="true"
FiltersTranslationProvider="GridFiltersTranslationProvider"
PageSize="10"
PageSizeSelectorVisible="true"
PageSizeSelectorItems="@(new int[] { 5,10,20 })"
Expand Down Expand Up @@ -30,6 +31,29 @@
@code {
private IEnumerable<Employee1> employees = default!;

private async Task<HashSet<FilterOperatorInfo>> GridFiltersTranslationProvider()
{
var filtersTranslation = new HashSet<FilterOperatorInfo>();

// 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<GridDataProviderResult<Employee1>> EmployeesDataProvider(GridDataProviderRequest<Employee1> request)
{
if (employees is null) // pull employees only one time for client-side filtering, sorting, and paging
Expand All @@ -56,4 +80,6 @@
new Employee1 { Id = 111, Name = "Glenda", Designation = "Data Engineer", DOJ = new DateOnly(1994, 1, 12), IsActive = true },
};
}


}
2 changes: 1 addition & 1 deletion blazorbootstrap/Components/Grid/Grid.razor
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<th class="@column.Class">
@if (column.Filterable)
{
<GridColumnFilter PropertyTypeName="@column.GetPropertyTypeName()"
<GridColumnFilter TItem="TItem" PropertyTypeName="@column.GetPropertyTypeName()"
FilterOperator="@column.FilterOperator"
FilterValue="@column.FilterValue"
FilterWidth="@column.FilterTextboxWidth"
Expand Down
32 changes: 19 additions & 13 deletions blazorbootstrap/Components/Grid/Grid.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,20 @@ private string GetPaginationItemsText()
builder.CloseElement(); // close: th
});

[Parameter, EditorRequired] public string ItemsPerPageText { get; set; } = "Items per page";

/// <summary>
/// This event is triggered when the user clicks on the row.
/// Set AllowRowClick to true to enable row clicking.
/// </summary>
[Parameter] public EventCallback<GridRowEventArgs<TItem>> OnRowClick { get; set; }

/// <summary>
/// This event is triggered when the user double clicks on the row.
/// Set AllowRowClick to true to enable row double clicking.
/// </summary>
[Parameter] public EventCallback<GridRowEventArgs<TItem>> OnRowDoubleClick { get; set; }

/// <summary>
/// Gets or sets the page size of the grid.
/// </summary>
Expand Down Expand Up @@ -676,18 +690,6 @@ private string GetPaginationItemsText()
/// </summary>
[Parameter] public bool Responsive { get; set; }

/// <summary>
/// This event is triggered when the user clicks on the row.
/// Set AllowRowClick to true to enable row clicking.
/// </summary>
[Parameter] public EventCallback<GridRowEventArgs<TItem>> OnRowClick { get; set; }

/// <summary>
/// This event is triggered when the user double clicks on the row.
/// Set AllowRowClick to true to enable row double clicking.
/// </summary>
[Parameter] public EventCallback<GridRowEventArgs<TItem>> OnRowDoubleClick { get; set; }

/// <summary>
/// This event is fired when the item selection changes.
/// </summary>
Expand All @@ -704,7 +706,11 @@ private string GetPaginationItemsText()
/// </summary>
[Parameter] public GridSettingsProviderDelegate SettingsProvider { get; set; } = default!;

[Parameter, EditorRequired] public string ItemsPerPageText { get; set; } = "Items per page";
/// <summary>
/// Filters transalation is for grid filters to render.
/// The provider should always return a 'FilterOperatorInfo' collection, and 'null' is not allowed.
/// </summary>
[Parameter] public GridFiltersTranslationDelegate FiltersTranslationProvider { get; set; } = default!;

#endregion Properties
}
1 change: 1 addition & 0 deletions blazorbootstrap/Components/Grid/GridColumnFilter.razor
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@namespace BlazorBootstrap
@inherits BaseComponent
@typeparam TItem

<div class="d-flex">
<button type="button" class="btn btn-light me-1 d-flex dropdown-toggle bb-grid-filter" data-bs-toggle="dropdown" aria-expanded="false">
Expand Down
4 changes: 3 additions & 1 deletion blazorbootstrap/Components/Grid/GridColumnFilter.razor.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace BlazorBootstrap;

public partial class GridColumnFilter : BaseComponent
public partial class GridColumnFilter<TItem> : BaseComponent
{
#region Members

Expand Down Expand Up @@ -120,6 +120,8 @@ or StringConstants.PropertyTypeNameDecimal

#region Properties

[CascadingParameter] public Grid<TItem> Grid { get; set; } = default!;

[Parameter] public EventCallback<FilterEventArgs> GridColumnFilterChanged { get; set; }

/// <summary>
Expand Down
6 changes: 6 additions & 0 deletions blazorbootstrap/Models/GridFiltersTranslationDelegate.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace BlazorBootstrap;

/// <summary>
/// Grid filters translation provider (delegate).
/// </summary>
public delegate Task<HashSet<FilterOperatorInfo>> GridFiltersTranslationDelegate();

0 comments on commit e5e3604

Please sign in to comment.