diff --git a/framework/src/Volo.Abp.MudBlazorUI/AbpMudCrudPageBase.cs b/framework/src/Volo.Abp.MudBlazorUI/AbpMudCrudPageBase.cs index 8f7be48e70..3dec8a2460 100644 --- a/framework/src/Volo.Abp.MudBlazorUI/AbpMudCrudPageBase.cs +++ b/framework/src/Volo.Abp.MudBlazorUI/AbpMudCrudPageBase.cs @@ -181,9 +181,7 @@ public abstract class AbpMudCrudPageBase< protected int CurrentPage = 1; protected string CurrentSorting = default!; - protected int? TotalCount; protected TGetListInput GetListInput = new TGetListInput(); - protected IReadOnlyList Entities = Array.Empty(); protected TCreateViewModel NewEntity; protected TKey EditingEntityId = default!; protected TUpdateViewModel EditingEntity; @@ -205,6 +203,8 @@ public abstract class AbpMudCrudPageBase< protected MudDialog? _createDialog; protected MudDialog? _editDialog; + protected AbpMudExtensibleDataGrid _dataGrid = default!; + protected AbpMudCrudPageBase() { NewEntity = new TCreateViewModel(); @@ -259,21 +259,6 @@ public abstract class AbpMudCrudPageBase< } } - protected virtual async Task GetEntitiesAsync() - { - try - { - await UpdateGetListInputAsync(); - var result = await AppService.GetListAsync(GetListInput); - Entities = MapToListViewModel(result.Items); - TotalCount = (int?)result.TotalCount; - } - catch (Exception ex) - { - await HandleErrorAsync(ex); - } - } - private IReadOnlyList MapToListViewModel(IReadOnlyList dtos) { if (typeof(TGetListOutputDto) == typeof(TListViewModel)) @@ -310,9 +295,12 @@ public abstract class AbpMudCrudPageBase< CurrentPage = 1; if (currentPage == 1) { - await GetEntitiesAsync(); + await _dataGrid.ReloadServerDataAsync(); + } + else + { + await InvokeAsync(StateHasChanged); } - await InvokeAsync(StateHasChanged); } protected virtual async Task> OnDataGridReadAsync(GridState state) @@ -322,14 +310,29 @@ public abstract class AbpMudCrudPageBase< .JoinAsString(","); CurrentPage = state.Page + 1; - await GetEntitiesAsync(); - await InvokeAsync(StateHasChanged); + try + { + await UpdateGetListInputAsync(); + var result = await AppService.GetListAsync(GetListInput); + var items = MapToListViewModel(result.Items); + + await InvokeAsync(StateHasChanged); - return new GridData + return new GridData + { + Items = items, + TotalItems = (int)result.TotalCount + }; + } + catch (Exception ex) { - Items = Entities, - TotalItems = TotalCount ?? 0 - }; + await HandleErrorAsync(ex); + return new GridData + { + Items = Array.Empty(), + TotalItems = 0 + }; + } } protected virtual async Task OpenCreateDialogAsync() @@ -450,7 +453,7 @@ public abstract class AbpMudCrudPageBase< protected virtual async Task OnCreatedEntityAsync() { - await GetEntitiesAsync(); + await _dataGrid.ReloadServerDataAsync(); await CloseCreateDialogAsync(); Snackbar.Add(GetCreateMessage(), Severity.Success); } @@ -495,7 +498,7 @@ public abstract class AbpMudCrudPageBase< protected virtual async Task OnUpdatedEntityAsync() { - await GetEntitiesAsync(); + await _dataGrid.ReloadServerDataAsync(); await CloseEditDialogAsync(); Snackbar.Add(GetUpdateMessage(), Severity.Success); } @@ -534,13 +537,7 @@ public abstract class AbpMudCrudPageBase< protected virtual async Task OnDeletedEntityAsync() { - if (Entities.Count == 1 && CurrentPage > 1) - { - CurrentPage -= 1; - } - - await GetEntitiesAsync(); - await InvokeAsync(StateHasChanged); + await _dataGrid.ReloadServerDataAsync(); Snackbar.Add(GetDeleteMessage(), Severity.Success); } diff --git a/framework/src/Volo.Abp.MudBlazorUI/Components/AbpMudExtensibleDataGrid.razor b/framework/src/Volo.Abp.MudBlazorUI/Components/AbpMudExtensibleDataGrid.razor index 2324311c46..6a56e9250c 100644 --- a/framework/src/Volo.Abp.MudBlazorUI/Components/AbpMudExtensibleDataGrid.razor +++ b/framework/src/Volo.Abp.MudBlazorUI/Components/AbpMudExtensibleDataGrid.razor @@ -2,283 +2,133 @@ @using MudBlazor @using Volo.Abp.Data -@if (ServerData is not null) -{ - - - - - - - @UiLocalizer["NoDataAvailableInDatatable"] - - - - @if (Columns != null) + + + + + + + @UiLocalizer["NoDataAvailableInDatatable"] + + + + @if (Columns != null) + { + @foreach (var column in Columns) { - @foreach (var column in Columns) + if (column.Actions.Any()) { - if (column.Actions.Any()) - { - var entityActionType = column.Actions.Count == 1 ? MudActionType.Button : MudActionType.Dropdown; - - - - @foreach (var action in column.Actions) + var entityActionType = column.Actions.Count == 1 ? MudActionType.Button : MudActionType.Dropdown; + + + + @foreach (var action in column.Actions) + { + if (action.ConfirmationMessage != null) { - if (action.ConfirmationMessage != null) - { - - - } - else - { - - - } + + + } + else + { + + } - + } + + + + } + else + { + @if (column.Component != null) + { + } else { - @if (column.Component != null) - { - - } - else + if (!ExtensionPropertiesRegex.IsMatch(column.Data)) { - if (!ExtensionPropertiesRegex.IsMatch(column.Data)) + @if (column.ValueConverter == null) { - @if (column.ValueConverter == null) - { - - - @if (ShowPager) - { - - } - - -} -else -{ - - - - - - - @UiLocalizer["NoDataAvailableInDatatable"] - - - - @if (Columns != null) - { - @foreach (var column in Columns) - { - if (column.Actions.Any()) - { - var entityActionType = column.Actions.Count == 1 ? MudActionType.Button : MudActionType.Dropdown; - - - - @foreach (var action in column.Actions) - { - if (action.ConfirmationMessage != null) + else + { + - - - } - else - { - @if (column.Component != null) - { - - } - else - { - if (!ExtensionPropertiesRegex.IsMatch(column.Data)) - { - @if (column.ValueConverter == null) - { - - - @if (ShowPager) - { - - } - - -} \ No newline at end of file + } + + + @if (ShowPager) + { + + } + + \ No newline at end of file diff --git a/framework/src/Volo.Abp.MudBlazorUI/Components/AbpMudExtensibleDataGrid.razor.cs b/framework/src/Volo.Abp.MudBlazorUI/Components/AbpMudExtensibleDataGrid.razor.cs index 24f31436a5..d25fe5d305 100644 --- a/framework/src/Volo.Abp.MudBlazorUI/Components/AbpMudExtensibleDataGrid.razor.cs +++ b/framework/src/Volo.Abp.MudBlazorUI/Components/AbpMudExtensibleDataGrid.razor.cs @@ -18,9 +18,9 @@ public partial class AbpMudExtensibleDataGrid : ComponentBase { protected const string DataFieldAttributeName = "Data"; - protected Regex ExtensionPropertiesRegex = new Regex(@"ExtraProperties\[(.*?)\]"); + private MudDataGrid? _dataGrid; - [Parameter] public IEnumerable? Data { get; set; } + protected Regex ExtensionPropertiesRegex = new Regex(@"ExtraProperties\[(.*?)\]"); [Parameter] public Func, Task>>? ServerData { get; set; } @@ -44,6 +44,14 @@ public partial class AbpMudExtensibleDataGrid : ComponentBase [Inject] public IStringLocalizer UiLocalizer { get; set; } = default!; + public virtual async Task ReloadServerDataAsync() + { + if (_dataGrid != null && ServerData != null) + { + await _dataGrid.ReloadServerData(); + } + } + protected virtual RenderFragment RenderCustomTableColumnComponent(Type type, object data) { return (builder) => diff --git a/modules/identity/src/Volo.Abp.Identity.Blazor.MudBlazor/Pages/Identity/RoleManagement.razor b/modules/identity/src/Volo.Abp.Identity.Blazor.MudBlazor/Pages/Identity/RoleManagement.razor index d230e6e705..2cb2322553 100644 --- a/modules/identity/src/Volo.Abp.Identity.Blazor.MudBlazor/Pages/Identity/RoleManagement.razor +++ b/modules/identity/src/Volo.Abp.Identity.Blazor.MudBlazor/Pages/Identity/RoleManagement.razor @@ -19,14 +19,13 @@ - + diff --git a/modules/identity/src/Volo.Abp.Identity.Blazor.MudBlazor/Pages/Identity/UserManagement.razor b/modules/identity/src/Volo.Abp.Identity.Blazor.MudBlazor/Pages/Identity/UserManagement.razor index 56889467cb..214aefccaf 100644 --- a/modules/identity/src/Volo.Abp.Identity.Blazor.MudBlazor/Pages/Identity/UserManagement.razor +++ b/modules/identity/src/Volo.Abp.Identity.Blazor.MudBlazor/Pages/Identity/UserManagement.razor @@ -31,14 +31,13 @@ - + diff --git a/modules/identity/src/Volo.Abp.Identity.Blazor.MudBlazor/Pages/Identity/UserManagement.razor.cs b/modules/identity/src/Volo.Abp.Identity.Blazor.MudBlazor/Pages/Identity/UserManagement.razor.cs index 3378b427f5..556d587879 100644 --- a/modules/identity/src/Volo.Abp.Identity.Blazor.MudBlazor/Pages/Identity/UserManagement.razor.cs +++ b/modules/identity/src/Volo.Abp.Identity.Blazor.MudBlazor/Pages/Identity/UserManagement.razor.cs @@ -93,7 +93,7 @@ public partial class UserManagement { GetListInput.Filter = GetListInput.Filter; CurrentPage = 1; - await GetEntitiesAsync(); + await _dataGrid.ReloadServerDataAsync(); } } diff --git a/modules/tenant-management/src/Volo.Abp.TenantManagement.Blazor.MudBlazor/Pages/TenantManagement/TenantManagement.razor b/modules/tenant-management/src/Volo.Abp.TenantManagement.Blazor.MudBlazor/Pages/TenantManagement/TenantManagement.razor index 930f0864df..78d6e7b4bd 100644 --- a/modules/tenant-management/src/Volo.Abp.TenantManagement.Blazor.MudBlazor/Pages/TenantManagement/TenantManagement.razor +++ b/modules/tenant-management/src/Volo.Abp.TenantManagement.Blazor.MudBlazor/Pages/TenantManagement/TenantManagement.razor @@ -3,6 +3,7 @@ @using global::MudBlazor @using Microsoft.AspNetCore.Authorization @using Volo.Abp.FeatureManagement.Blazor.MudBlazor.Components +@using Volo.Abp.MudBlazorUI.Components @using Microsoft.Extensions.Localization @using Volo.Abp.UI.Navigation.Localization.Resource @inject IStringLocalizer LUiNavigation @@ -14,10 +15,10 @@ - diff --git a/modules/tenant-management/src/Volo.Abp.TenantManagement.Blazor/Pages/TenantManagement/TenantManagement.razor b/modules/tenant-management/src/Volo.Abp.TenantManagement.Blazor/Pages/TenantManagement/TenantManagement.razor index f87467f8c2..0ebfa9808f 100644 --- a/modules/tenant-management/src/Volo.Abp.TenantManagement.Blazor/Pages/TenantManagement/TenantManagement.razor +++ b/modules/tenant-management/src/Volo.Abp.TenantManagement.Blazor/Pages/TenantManagement/TenantManagement.razor @@ -24,7 +24,6 @@ @* ************************* DATA GRID ************************* *@