Class TableProvider
- Namespace
- Htmx.Components.Table
- Assembly
- Htmx.Components.dll
Default implementation of ITableProvider that provides table data processing capabilities.
public class TableProvider : ITableProvider
- Inheritance
-
TableProvider
- Implements
- Inherited Members
- Extension Methods
Remarks
This implementation provides filtering, sorting, and pagination functionality. It integrates with the page state system to maintain table state across requests.
Constructors
TableProvider(IPageState)
Initializes a new instance of the TableProvider class.
public TableProvider(IPageState pageState)
Parameters
pageStateIPageStateThe page state service for maintaining table state across requests.
Exceptions
- ArgumentNullException
Thrown when
pageStateis null.
Methods
FetchPageAsync<T, TKey>(TableModel<T, TKey>, IQueryable<T>, TableState)
Uses the given columns and tableState to extend the given queryable for appropriate filtering and sorting, and then executes the query twice; once to count rows so that PageCount can be calculated, and once with pagination applied. Places the results in the given TableModel<T, TKey>.
public Task FetchPageAsync<T, TKey>(TableModel<T, TKey> tableModel, IQueryable<T> query, TableState tableState) where T : class
Parameters
tableModelTableModel<T, TKey>The table model to populate with data and metadata.
queryIQueryable<T>The queryable to execute.
tableStateTableStateThe current state of the table including filters, sorting, and pagination.
Returns
- Task
A task that represents the asynchronous operation.
Type Parameters
TThe entity type being queried.
TKeyThe key type for the entity.
Remarks
The method processes the query in the following order:
- Applies text-based filtering using column filter delegates
- Applies range-based filtering for date/numeric ranges
- Applies sorting based on the current sort column and direction
- Executes a count query to determine total records and page count
- Applies pagination and executes the data query
- Populates the table model with rows and metadata
Exceptions
- ArgumentNullException
Thrown when any parameter is null.
- InvalidOperationException
Thrown when no sortable column is found for default sorting.