Class MudTablePageBase<TItem, TFilter, TOrdering>
- Namespace
- NuvTools.AspNetCore.Blazor.MudBlazor.Components
- Assembly
- NuvTools.AspNetCore.Blazor.MudBlazor.dll
Abstract base class for pages with server-side paged lists using MudBlazor MudTable.
public abstract class MudTablePageBase<TItem, TFilter, TOrdering> : ComponentBase, IComponent, IHandleEvent, IHandleAfterRender where TFilter : PagingFilter<TOrdering> where TOrdering : struct, Enum
Type Parameters
TItemThe type of DTO displayed in the table.
TFilterThe filter type that inherits from PagingFilter<T>.
TOrderingThe enum type for sorting options.
- Inheritance
-
MudTablePageBase<TItem, TFilter, TOrdering>
- Implements
- Inherited Members
Examples
public class UserListPage : MudTablePageBase<UserDto, UserFilter, UserSortColumn>
{
[Inject] private IUserService UserService { get; set; } = default!;
protected override string SessionStorageKey => "user-list-filter";
protected override UserFilter CreateDefaultFilter() => new()
{
SortColumn = UserSortColumn.Name,
PageSize = 25
};
protected override async Task<IResult<PagingWithEnumerableList<UserDto>>> FetchDataAsync(
UserFilter filter, CancellationToken cancellationToken)
{
return await UserService.GetUsersAsync(filter, cancellationToken);
}
protected override UserSortColumn MapSortLabelToOrdering(string sortLabel)
{
return Enum.Parse<UserSortColumn>(sortLabel);
}
}
Remarks
This base class provides:
- Session storage persistence for filter state
- Integration with ILoadingService for loading indicators
- MudTable server-side data binding
- Sort direction mapping between NuvTools and MudBlazor
- Support for SkipCount to avoid expensive COUNT queries on large datasets
Properties
CurrentPage
Gets or sets the current page index (0-based, same as MudBlazor and NuvTools.Data).
public int CurrentPage { get; set; }
Property Value
HasNextPage
Gets whether the current paged data has more items beyond the current page. Useful for infinite scroll or forward-only navigation scenarios with SkipCount.
public bool HasNextPage { get; }
Property Value
IsFirstPage
Gets whether the current page is the first page (page index is 0).
public bool IsFirstPage { get; }
Property Value
LoadingService
Gets or sets the loading service for managing loading indicator state. This service is optional and null-safe.
[Inject]
protected ILoadingService? LoadingService { get; set; }
Property Value
ModelFilter
Gets or sets the current filter model.
public TFilter ModelFilter { get; set; }
Property Value
- TFilter
PagedData
Gets or sets the paged data returned from the API.
public PagingWithEnumerableList<TItem>? PagedData { get; set; }
Property Value
- PagingWithEnumerableList<TItem>
SessionStorage
Gets or sets the session storage service for persisting filter state.
[Inject]
protected ISessionStorageService SessionStorage { get; set; }
Property Value
SessionStorageKey
Gets the session storage key for persisting the filter state.
protected abstract string SessionStorageKey { get; }
Property Value
Table
Gets or sets the reference to the MudTable component.
public MudTable<TItem> Table { get; set; }
Property Value
- MudTable<TItem>
Methods
CreateDefaultFilter()
Creates the default filter when no stored filter exists.
protected abstract TFilter CreateDefaultFilter()
Returns
- TFilter
A new instance of the filter with default values.
FetchDataAsync(TFilter, CancellationToken)
Fetches data from the API service.
protected abstract Task<IResult<PagingWithEnumerableList<TItem>>> FetchDataAsync(TFilter filter, CancellationToken cancellationToken)
Parameters
filterTFilterThe filter to apply.
cancellationTokenCancellationTokenThe cancellation token.
Returns
- Task<IResult<PagingWithEnumerableList<TItem>>>
The paged result containing the data.
GetSortDirection()
Converts NuvTools SortDirection to MudBlazor SortDirection.
public SortDirection GetSortDirection()
Returns
- SortDirection
The MudBlazor sort direction.
GetSortLabel()
Converts the current ordering enum value to a sort label string. Default implementation uses ToString().
public virtual string GetSortLabel()
Returns
- string
The sort label string.
MapSortLabelToOrdering(string)
Maps a MudBlazor sort label string to the ordering enum value.
protected abstract TOrdering MapSortLabelToOrdering(string sortLabel)
Parameters
sortLabelstringThe sort label from MudBlazor.
Returns
- TOrdering
The corresponding enum value.
NextPageAsync()
Navigates to the next page. Useful for custom navigation with SkipCount.
protected Task NextPageAsync()
Returns
- Task
A task representing the asynchronous operation.
OnDataLoadedAsync(PagingWithEnumerableList<TItem>)
Called after data is successfully loaded. Override to perform post-load operations.
protected virtual Task OnDataLoadedAsync(PagingWithEnumerableList<TItem> data)
Parameters
dataPagingWithEnumerableList<TItem>The loaded paged data.
Returns
- Task
A task representing the asynchronous operation.
OnFetchDataFailed(IResult)
Called when data fetch fails. Override to customize error handling.
protected virtual void OnFetchDataFailed(IResult result)
Parameters
resultIResultThe failed result containing error details.
OnInitializedAsync()
Method invoked when the component is ready to start, having received its initial parameters from its parent in the render tree.
Override this method if you will perform an asynchronous operation and want the component to refresh when that operation is completed.
protected override Task OnInitializedAsync()
Returns
OnInitializedFilterAsync()
Called during OnInitializedAsync() after filter initialization. Override to load lookup data, breadcrumbs, etc.
protected virtual Task OnInitializedFilterAsync()
Returns
- Task
A task representing the asynchronous operation.
OnInitializingAsync()
Called during OnInitializedAsync() before filter initialization. Override to perform additional setup.
protected virtual Task OnInitializingAsync()
Returns
- Task
A task representing the asynchronous operation.
PreviousPageAsync()
Navigates to the previous page. Useful for custom navigation with SkipCount.
protected Task PreviousPageAsync()
Returns
- Task
A task representing the asynchronous operation.
ReloadTableAsync()
Helper method to reload the table data.
protected Task ReloadTableAsync()
Returns
- Task
A task representing the asynchronous operation.
SaveFilterAsync()
Called to save the filter to session storage. Override to customize save behavior (e.g., exclude transient properties from filter).
protected virtual Task SaveFilterAsync()
Returns
- Task
A task representing the asynchronous operation.
ServerReload(TableState, CancellationToken)
Server reload method for MudTable binding.
public Task<TableData<TItem>> ServerReload(TableState state, CancellationToken cancellationToken)
Parameters
stateTableStateThe table state from MudBlazor.
cancellationTokenCancellationTokenThe cancellation token.
Returns
- Task<TableData<TItem>>
The table data for MudBlazor.