Table of Contents

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 uses Entity Framework Core for data access and 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

pageState IPageState

The page state service for maintaining table state across requests.

Exceptions

ArgumentNullException

Thrown when pageState is 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 with .CountAsync() so that PageCount can be calculated, and once with pagination applied. Places the results in the given TableModel<T, TKey>. The queryable is expected to be an EF Core queryable.

public Task FetchPageAsync<T, TKey>(TableModel<T, TKey> tableModel, IQueryable<T> query, TableState tableState) where T : class

Parameters

tableModel TableModel<T, TKey>

The table model to populate with data and metadata.

query IQueryable<T>

The Entity Framework Core queryable to execute.

tableState TableState

The current state of the table including filters, sorting, and pagination.

Returns

Task

A task that represents the asynchronous operation.

Type Parameters

T

The entity type being queried.

TKey

The key type for the entity.

Remarks

The method processes the query in the following order:

  1. Applies text-based filtering using column filter delegates
  2. Applies range-based filtering for date/numeric ranges
  3. Applies sorting based on the current sort column and direction
  4. Executes a count query to determine total records and page count
  5. Applies pagination and executes the data query
  6. 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.