Class MudTable<T>
- Namespace
- MudBlazor
- Assembly
- MudBlazor.dll
A sortable, filterable table with multiselection and pagination.
public class MudTable<T> : MudTableBase, IComponent, IHandleEvent, IHandleAfterRender, IMudStateHasChanged, IDisposable
Type Parameters
T
The type of item displayed in this table.
- Inheritance
-
MudTable<T>
- Implements
- Inherited Members
- Extension Methods
Constructors
MudTable()
public MudTable()
Properties
ChildRowContent
The optional nested content underneath each row.
[Parameter]
[Category("Rows")]
public RenderFragment<T>? ChildRowContent { get; set; }
Property Value
Remarks
Columns
The columns for each row in this table.
[Parameter]
[Category("Behavior")]
public RenderFragment<T>? Columns { get; set; }
Property Value
Comparer
The comparer used to determine selected items.
[Parameter]
[Category("Behavior")]
public IEqualityComparer<T>? Comparer { get; set; }
Property Value
Context
Gets the current state of the table.
public TableContext<T> Context { get; }
Property Value
- TableContext<T>
CurrentPageItems
protected IEnumerable<T> CurrentPageItems { get; }
Property Value
- IEnumerable<T>
Def
protected T? Def { get; }
Property Value
- T
Filter
The function which determines whether an item should be displayed.
[Parameter]
[Category("Filtering")]
public Func<T, bool>? Filter { get; set; }
Property Value
Remarks
Typically used to implement custom filtering.
FilteredItems
The table items after filters are applied.
public IEnumerable<T> FilteredItems { get; }
Property Value
- IEnumerable<T>
Remarks
When ServerData is set, the latest items are returned. When Filter is set, filtered items are returned.
GroupBy
Defines how rows are grouped together.
[Parameter]
[Category("Grouping")]
public TableGroupDefinition<T>? GroupBy { get; set; }
Property Value
Remarks
Groups can be defined in multiple levels.
GroupFooterClass
The custom CSS classes to apply to each group footer row.
[Parameter]
[Category("Grouping")]
public string? GroupFooterClass { get; set; }
Property Value
Remarks
Multiple classes must be separated by spaces.
GroupFooterStyle
The custom CSS styles to apply to each group footer row.
[Parameter]
[Category("Grouping")]
public string? GroupFooterStyle { get; set; }
Property Value
GroupFooterTemplate
The content for the footer of each group when GroupBy is set.
[Parameter]
[Category("Grouping")]
public RenderFragment<TableGroupData<object, T>>? GroupFooterTemplate { get; set; }
Property Value
Remarks
Use MudTd to define the cells in the group footer.
GroupHeaderClass
The custom CSS classes to apply to each group header row.
[Parameter]
[Category("Grouping")]
public string? GroupHeaderClass { get; set; }
Property Value
Remarks
Multiple classes must be separated by spaces.
GroupHeaderStyle
The custom CSS styles to apply to each group header row.
[Parameter]
[Category("Grouping")]
public string? GroupHeaderStyle { get; set; }
Property Value
GroupHeaderTemplate
The content for the header of each group when GroupBy is set.
[Parameter]
[Category("Grouping")]
public RenderFragment<TableGroupData<object, T>>? GroupHeaderTemplate { get; set; }
Property Value
Remarks
Use MudTd to define the cells in the group header.
HorizontalScrollbar
Shows a horizontal scroll bar if the content exceeds the maximum width.
[Parameter]
[Category("Behavior")]
public bool HorizontalScrollbar { get; set; }
Property Value
Remarks
Defaults to false
. Typically true
for tables with more columns than can fit on the screen.
Items
The data to display.
[Parameter]
[Category("Data")]
public IEnumerable<T>? Items { get; set; }
Property Value
- IEnumerable<T>
Remarks
When set, ServerData should not be set. Use that property to get data from a back end.
LoadingContent
The content shown while table data is loading and the table has no rows.
[Parameter]
[Category("Data")]
public RenderFragment? LoadingContent { get; set; }
Property Value
NoRecordsContent
The content shown when there are no rows to display.
[Parameter]
[Category("Data")]
public RenderFragment? NoRecordsContent { get; set; }
Property Value
Remarks
NumPages
protected override int NumPages { get; }
Property Value
OnRowClick
Occurs when a row has been clicked.
[Parameter]
public EventCallback<TableRowClickEventArgs<T>> OnRowClick { get; set; }
Property Value
OnRowMouseEnter
Occurs when the pointer hovers over a row.
[Parameter]
public EventCallback<TableRowHoverEventArgs<T>> OnRowMouseEnter { get; set; }
Property Value
OnRowMouseLeave
Occurs when the pointer is no longer hovering over a row.
[Parameter]
public EventCallback<TableRowHoverEventArgs<T>> OnRowMouseLeave { get; set; }
Property Value
RowClassFunc
The function which returns CSS classes for a row.
[Parameter]
[Category("Rows")]
public Func<T, int, string>? RowClassFunc { get; set; }
Property Value
Remarks
The current item and row index are provided to the function. Multiple classes must be separated by spaces.
RowEditableFunc
The function which determines if a row can be edited.
[Parameter]
[Category("Editing")]
public Func<T, bool>? RowEditableFunc { get; set; }
Property Value
Remarks
Make the function return true
to allow editing, and false
to prevent it. When no value is set, all rows are considered editable.
RowEditingTemplate
The columns for each row when a row is being edited.
[Parameter]
[Category("Editing")]
public RenderFragment<T>? RowEditingTemplate { get; set; }
Property Value
Remarks
Use MudTd to define columns, and context
to access item properties for each column. Typically looks similar to rows in RowTemplate but with edit components.
RowStyleFunc
The function which returns CSS styles for a row.
[Parameter]
[Category("Rows")]
public Func<T, int, string>? RowStyleFunc { get; set; }
Property Value
Remarks
The current item and row index are provided to the function.
RowTemplate
The columns for each row in this table.
[Parameter]
[Category("Rows")]
public RenderFragment<T>? RowTemplate { get; set; }
Property Value
Remarks
Use MudTd to define columns, and context
to access item properties for each column.
SelectedItem
The currently selected item when MultiSelection
is false
.
[Parameter]
[Category("Selecting")]
public T? SelectedItem { get; set; }
Property Value
- T
Remarks
When the selected item changes, the SelectedItemChanged event occurs. When MultiSelection
is true
, use the SelectedItems property.
SelectedItemChanged
Occurs when SelectedItem has changed.
[Parameter]
public EventCallback<T> SelectedItemChanged { get; set; }
Property Value
Remarks
Occurs when MultiSelection
is false
, otherwise SelectedItemsChanged occurs.
SelectedItems
The currently selected item when MultiSelection
is true
.
[Parameter]
[Category("Selecting")]
public HashSet<T>? SelectedItems { get; set; }
Property Value
- HashSet<T>
Remarks
When the selected items change, the SelectedItemsChanged event occurs. When MultiSelection
is false
, use the SelectedItem property.
SelectedItemsChanged
Occurs when SelectedItems has changed.
[Parameter]
public EventCallback<HashSet<T>> SelectedItemsChanged { get; set; }
Property Value
- EventCallback<HashSet<T>>
Remarks
Occurs when MultiSelection
is true
, otherwise SelectedItemChanged occurs.
ServerData
Gets the sorted and paginated data for the table.
[Parameter]
[Category("Data")]
public Func<TableState, CancellationToken, Task<TableData<T>>>? ServerData { get; set; }
Property Value
- Func<TableState, CancellationToken, Task<TableData<T>>>
Remarks
Use the provided TableState to request items for a specific page index, page size, sort column, and sort order.
Return a TableData<T> which contains the requested page of items and the total number of items (excluding pagination).
Forward the CancellationToken to methods which support it such as HttpClient
and DbContext
to cancel ongoing requests.
When this parameter is set, Items and Filter should not be set.
TableContext
Gets the current state of the table.
public override TableContext TableContext { get; }
Property Value
Methods
BuildRenderTree(RenderTreeBuilder)
protected override void BuildRenderTree(RenderTreeBuilder __builder)
Parameters
__builder
RenderTreeBuilder
CollapseAllGroups()
Collapses all groups within this table.
public void CollapseAllGroups()
ContainsItem(object?)
Gets whether Items contains the specified item.
public override bool ContainsItem(object? item)
Parameters
item
objectThe item to find.
Returns
- bool
When
true
, the item was found, otherwisefalse
.
Dispose()
Releases resources used by this table.
public void Dispose()
Dispose(bool)
protected virtual void Dispose(bool disposing)
Parameters
disposing
bool
ExpandAllGroups()
Expands all groups within this table.
public void ExpandAllGroups()
GetFilteredItemsCount()
Gets the number of filtered items.
public override int GetFilteredItemsCount()
Returns
- int
When ServerData is set, the total number of items, otherwise the number of FilteredItems.
GetItemsOfPage(int, int)
protected IEnumerable<T> GetItemsOfPage(int n, int pageSize)
Parameters
Returns
- IEnumerable<T>
IsCheckedRow(T)
Checks if the row is selected. If there is set a Comparer, uses the comparer, otherwise uses a direct contains
protected bool IsCheckedRow(T item)
Parameters
item
T
Returns
OnAfterRender(bool)
protected override void OnAfterRender(bool firstRender)
Parameters
firstRender
bool
OnAfterRenderAsync(bool)
protected override Task OnAfterRenderAsync(bool firstRender)
Parameters
firstRender
bool
Returns
OnInitialized()
protected override void OnInitialized()
ReloadServerData()
Reloads this table's data via the ServerData function.
public Task ReloadServerData()
Returns
Remarks
Use this method to reload this table's results when ServerData is set.
SetEditingItem(object?)
Sets the item to edit.
public override void SetEditingItem(object? item)
Parameters
item
objectThe item to edit.
SetSelectedItem(object?)
Sets the SelectedItem.
public override void SetSelectedItem(object? item)
Parameters
item
objectThe new value to set.
UpdateSelection()
Raises the SelectedItemsChanged event.
public override void UpdateSelection()