diff --git a/BlazorBootstrap.Demo.RCL/Components/Pages/Grid/GridDocumentation.razor b/BlazorBootstrap.Demo.RCL/Components/Pages/Grid/GridDocumentation.razor index b53d04b70..3baef2a9c 100644 --- a/BlazorBootstrap.Demo.RCL/Components/Pages/Grid/GridDocumentation.razor +++ b/BlazorBootstrap.Demo.RCL/Components/Pages/Grid/GridDocumentation.razor @@ -9,7 +9,7 @@ Use Blazor Bootstrap grid component to display tabular data from the data source. And it supports client-side and server-side filtering, paging & sorting. -@* +
For filtering, AllowFiltering and PropertyName parameters are required.
@@ -206,10 +206,10 @@ - - *@ + + - + @code { diff --git a/BlazorBootstrap.Demo.RCL/Components/Pages/Grid/Grid_Demo_21_Specify_Custom_Column_Header.razor b/BlazorBootstrap.Demo.RCL/Components/Pages/Grid/Grid_Demo_21_Specify_Custom_Column_Header.razor index 10b4e4761..4a8f294e4 100644 --- a/BlazorBootstrap.Demo.RCL/Components/Pages/Grid/Grid_Demo_21_Specify_Custom_Column_Header.razor +++ b/BlazorBootstrap.Demo.RCL/Components/Pages/Grid/Grid_Demo_21_Specify_Custom_Column_Header.razor @@ -35,8 +35,8 @@ private bool IsAllChecked { - get => employees.All(e => e.IsActive); - set => Array.ForEach(employees.ToArray(), e => e.IsActive = value); + get => employees?.All(e => e.IsActive) ?? false; + set => Array.ForEach(employees?.ToArray()!, e => e.IsActive = value); } private async Task> EmployeesDataProvider(GridDataProviderRequest request) diff --git a/BlazorBootstrap.Demo.RCL/Components/Pages/Grid/Grid_Demo_24_Disable_Selection.razor b/BlazorBootstrap.Demo.RCL/Components/Pages/Grid/Grid_Demo_24_Disable_Selection.razor index 3dca7f74d..f1b741ea6 100644 --- a/BlazorBootstrap.Demo.RCL/Components/Pages/Grid/Grid_Demo_24_Disable_Selection.razor +++ b/BlazorBootstrap.Demo.RCL/Components/Pages/Grid/Grid_Demo_24_Disable_Selection.razor @@ -71,7 +71,7 @@ private bool DisableAllRowsSelectionHandler(IEnumerable employees) { - return employees.Any(x => x.Id < 105); // disable selection if EmployeeId < 105 + return employees?.Any(x => x.Id < 105) ?? false; // disable selection if EmployeeId < 105 } private bool DisableRowSelectionHandler(Employee1 emp) diff --git a/BlazorBootstrap.Demo.RCL/Components/Pages/Grid/Grid_Demo_35_Enum_Filters.razor b/BlazorBootstrap.Demo.RCL/Components/Pages/Grid/Grid_Demo_35_Enum_Filters.razor index 50ca02a0f..d37795b09 100644 --- a/BlazorBootstrap.Demo.RCL/Components/Pages/Grid/Grid_Demo_35_Enum_Filters.razor +++ b/BlazorBootstrap.Demo.RCL/Components/Pages/Grid/Grid_Demo_35_Enum_Filters.razor @@ -14,7 +14,7 @@ @context.DOB - + @context.Status diff --git a/BlazorBootstrap.Demo.RCL/Components/Pages/Grid/Grid_Demo_36_Guid_Filters.razor b/BlazorBootstrap.Demo.RCL/Components/Pages/Grid/Grid_Demo_36_Guid_Filters.razor index a9a3cd880..013d92d84 100644 --- a/BlazorBootstrap.Demo.RCL/Components/Pages/Grid/Grid_Demo_36_Guid_Filters.razor +++ b/BlazorBootstrap.Demo.RCL/Components/Pages/Grid/Grid_Demo_36_Guid_Filters.razor @@ -5,19 +5,19 @@ AllowFiltering="true" Responsive="true"> - + @context.Oid - + @context.Id - + @context.Name @context.DOB - + @context.Status diff --git a/blazorbootstrap/Components/Grid/Grid.razor b/blazorbootstrap/Components/Grid/Grid.razor index 09eb6fd94..6218b1d80 100644 --- a/blazorbootstrap/Components/Grid/Grid.razor +++ b/blazorbootstrap/Components/Grid/Grid.razor @@ -66,30 +66,39 @@ } - @if (requestInProgress) //|| totalCount == null + @{ + var columnCount = AllowSelection ? columns.Count + 1 : columns.Count; + } + @if (requestInProgress) //|| totalCount is null { - // show placeholders - @for (var i = 0; i < 5; i++) + @if (LoadingTemplate is null) { - - @for (var j = 0; j < columns.Count; j++) - { - - - - } - + // show placeholders + @for (var i = 0; i < 5; i++) + { + + @for (var j = 0; j < columnCount; j++) + { + + + + } + + } + } + else + { +
+ @LoadingTemplate +
} } else if (totalCount == 0) { // show empty - @{ - var columnCount = AllowSelection ? columns.Count + 1 : columns.Count; - } - @if (EmptyDataTemplate == null) + @if (EmptyDataTemplate is null) {
@@ -109,7 +118,7 @@ } else if (totalCount > 0) { - if (items != null) + if (items is not null) { var rowIndex = 0; foreach (var item in items) diff --git a/blazorbootstrap/Components/Grid/Grid.razor.cs b/blazorbootstrap/Components/Grid/Grid.razor.cs index fb51a9a1a..4ba7a6b04 100644 --- a/blazorbootstrap/Components/Grid/Grid.razor.cs +++ b/blazorbootstrap/Components/Grid/Grid.razor.cs @@ -144,6 +144,10 @@ internal async Task RefreshDataAsync(bool firstRender = false, CancellationToken requestInProgress = true; + await InvokeAsync(StateHasChanged); // chnage the state to show the loading + + await Task.Delay(300); + if (firstRender) await LoadGridSettingsAsync(); @@ -696,6 +700,11 @@ private void SetFilters(IEnumerable filterItems) //[EditorRequired] public string ItemsPerPageText { get; set; } = "Items per page"!; + /// + /// Template to render when the grid is loading. + /// + public RenderFragment LoadingTemplate { get; set; } = default!; + /// /// This event is triggered when the user clicks on the row. /// Set AllowRowClick to true to enable row clicking. diff --git a/blazorbootstrap/Components/Grid/GridColumnFilter.razor b/blazorbootstrap/Components/Grid/GridColumnFilter.razor index 153440c07..617cf385c 100644 --- a/blazorbootstrap/Components/Grid/GridColumnFilter.razor +++ b/blazorbootstrap/Components/Grid/GridColumnFilter.razor @@ -55,7 +55,7 @@ else if (PropertyTypeName == StringConstants.PropertyTypeNameEnum) { - + @if (string.IsNullOrWhiteSpace(filterValue)) { Select diff --git a/blazorbootstrap/Components/Grid/GridColumnFilter.razor.cs b/blazorbootstrap/Components/Grid/GridColumnFilter.razor.cs index 78299665c..0b505d31f 100644 --- a/blazorbootstrap/Components/Grid/GridColumnFilter.razor.cs +++ b/blazorbootstrap/Components/Grid/GridColumnFilter.razor.cs @@ -160,7 +160,7 @@ or StringConstants.PropertyTypeNameDecimal [Parameter] public GridFiltersTranslationDelegate FiltersTranslationProvider { get; set; } = default!; - private string filterStyle => FilterWidth > 0 ? $"width:{FilterWidth.ToString(CultureInfo.InvariantCulture)}{Unit};" : ""; + private string filterStyle => FilterWidth > 0 ? $"width:{FilterWidth.ToString(CultureInfo.InvariantCulture)}{Unit.ToString().ToLower()};" : ""; /// /// Gets or sets filter value. diff --git a/docs/docs/05-components/grid.mdx b/docs/docs/05-components/grid.mdx index 1a4b956a1..1ff738f81 100644 --- a/docs/docs/05-components/grid.mdx +++ b/docs/docs/05-components/grid.mdx @@ -3134,3 +3134,172 @@ Automatically hides the paging controls when the grid item count is less than or ``` [See demo here](https://demos.blazorbootstrap.com/grid#auto-hide-paging) + +### Enum filter + +Blazor Bootstrap: Grid Component - Enum filter + +```cshtml {} showLineNumbers + + + + @context.Id + + + @context.Name + + + @context.DOB + + + @context.Status + + + +``` + +```cshtml {} showLineNumbers +@code { + BlazorBootstrap.Grid grid = default!; + private IEnumerable users = default!; + + protected override async Task OnAfterRenderAsync(bool firstRender) + { + await base.OnAfterRenderAsync(firstRender); + } + + private async Task> UsersDataProvider(GridDataProviderRequest request) + { + if (users is null) // pull employees only one time for client-side filtering, sorting, and paging + users = GetUsers(); // call a service or an API to pull the employees + + return await Task.FromResult(request.ApplyTo(users)); + } + + private IEnumerable GetUsers() + { + return new List + { + new User { Id = 107, Name = "Alice", DOB = new DateOnly(1998, 11, 17), Status = UserStatus.Registered }, + new User { Id = null, Name = "Bob", DOB = new DateOnly(1985, 1, 5), Status = UserStatus.Verified }, + new User { Id = 106, Name = "John", DOB = new DateOnly(1995, 4, 17), Status = UserStatus.Registered }, + new User { Id = 104, Name = "Pop", DOB = new DateOnly(1985, 6, 8), Status = UserStatus.Registered }, + new User { Id = 105, Name = "Ronald", DOB = new DateOnly(1991, 8, 23), Status = UserStatus.VerificationPending }, + new User { Id = 102, Name = "Line", DOB = new DateOnly(1977, 1, 12), Status = UserStatus.VerificationPending }, + new User { Id = 101, Name = "Daniel", DOB = new DateOnly(1977, 1, 12), Status = UserStatus.Registered }, + new User { Id = 108, Name = "Zayne", DOB = new DateOnly(1991, 1, 1), Status = UserStatus.Verified }, + new User { Id = 109, Name = "Isha", DOB = null, Status = UserStatus.Verified }, + new User { Id = 110, Name = "Vijay", DOB = new DateOnly(1990, 7, 1), Status = UserStatus.Verified }, + }; + } + + public record class User + { + public int? Id { get; set; } + public string? Name { get; set; } + public DateOnly? DOB { get; set; } + public UserStatus Status { get; set; } + } + + public enum UserStatus + { + Registered, + VerificationPending, + Verified + } +} +``` + +[See demo here](https://demos.blazorbootstrap.com/grid#enum-filter) + +### Guid filter + +Blazor Bootstrap: Grid Component - Guid filter + +```cshtml { + + + + @context.Oid + + + @context.Id + + + @context.Name + + + @context.DOB + + + @context.Status + + + +} showLineNumbers +``` + +```cshtml {} showLineNumbers +@code { + BlazorBootstrap.Grid grid = default!; + private IEnumerable users = default!; + + protected override async Task OnAfterRenderAsync(bool firstRender) + { + await base.OnAfterRenderAsync(firstRender); + } + + private async Task> UsersDataProvider(GridDataProviderRequest request) + { + if (users is null) // pull employees only one time for client-side filtering, sorting, and paging + users = GetUsers(); // call a service or an API to pull the employees + + return await Task.FromResult(request.ApplyTo(users)); + } + + private IEnumerable GetUsers() + { + return new List + { + new User { Oid = Guid.NewGuid(), Id = 107, Name = "Alice", DOB = new DateOnly(1998, 11, 17), Status = UserStatus.Registered }, + new User { Oid = Guid.NewGuid(), Id = null, Name = "Bob", DOB = new DateOnly(1985, 1, 5), Status = UserStatus.Verified }, + new User { Oid = Guid.NewGuid(), Id = 106, Name = "John", DOB = new DateOnly(1995, 4, 17), Status = UserStatus.Registered }, + new User { Oid = Guid.NewGuid(), Id = 104, Name = "Pop", DOB = new DateOnly(1985, 6, 8), Status = UserStatus.Registered }, + new User { Oid = Guid.NewGuid(), Id = 105, Name = "Ronald", DOB = new DateOnly(1991, 8, 23), Status = UserStatus.VerificationPending }, + new User { Oid = Guid.NewGuid(), Id = 102, Name = "Line", DOB = new DateOnly(1977, 1, 12), Status = UserStatus.VerificationPending }, + new User { Oid = Guid.NewGuid(), Id = 101, Name = "Daniel", DOB = new DateOnly(1977, 1, 12), Status = UserStatus.Registered }, + new User { Oid = Guid.NewGuid(), Id = 108, Name = "Zayne", DOB = new DateOnly(1991, 1, 1), Status = UserStatus.Verified }, + new User { Oid = Guid.NewGuid(), Id = 109, Name = "Isha", DOB = null, Status = UserStatus.Verified }, + new User { Oid = Guid.NewGuid(), Id = 110, Name = "Vijay", DOB = new DateOnly(1990, 7, 1), Status = UserStatus.Verified }, + }; + } + + public record class User + { + public Guid Oid { get; set; } + public int? Id { get; set; } + public string? Name { get; set; } + public DateOnly? DOB { get; set; } + public UserStatus Status { get; set; } + } + + public enum UserStatus + { + Registered, + VerificationPending, + Verified + } +} +``` + +[See demo here](https://demos.blazorbootstrap.com/grid#guid-filter)