AdminTable Component and Associated APIs
The AdminTable is a versatile Vue component designed for displaying and managing tabular data within an admin interface. It offers features like pagination, sorting, filtering, column visibility control, and row selection.

AdminTable Component
app/components/AdminTable/index.vue
The core component, orchestrates the display and interaction of the table.
Key Features:
- Data Fetching: Accepts a
fetchDataprop, a function responsible for retrieving data based on pagination, sorting, and filtering parameters. - Column Definition: Uses a
columnsprop to define the table structure, including headers and data accessors. - Filtering: Supports various filter types (
input,checkbox,tabs,daterange) defined via thefiltersprop. Filter changes trigger data refetching. - Pagination: Integrates a component, with page number and items per page synced with URL query parameters.
- Sorting: Sort options are also synced with URL query parameters.
- Column Visibility: Leverages the composable and component to allow users to show/hide columns.
- Row Selection: If
canSelectis true, it enables row selection functionality, managed by the composable. - State Management: Component state (page, limit, sort options) is reactive and synchronized with the URL query parameters for better user experience and shareability.
- Error Handling: Includes basic error handling for data fetching operations, displaying toast notifications on failure.
- Refresh Functionality: Provides a
handleRefreshmethod to manually refetch table data.
Backend APIs
Two main API endpoints support the AdminTable component:
List API (
/api/admin/list/[tableName].get.ts)- This dynamic GET endpoint retrieves a paginated and filtered list of records for a specified
tableName. - Path Parameter:
tableName(string) - The name of the database table to query. - Query Parameters:
page(number, optional, default: 1): The page number for pagination.limit(number, optional, default: 20, max: 100): The number of items per page.filter(string, optional): A JSON string representing an array of filter conditions (e.g.,[{ "col": "name", "op": "like", "v": "test" }]).sort(string, optional): A JSON string representing an array of sort conditions (e.g.,[[ "createdAt", "desc" ]]).
- Functionality:
- Validates the
tableName. - Parses and applies
filterandsortquery parameters. - Applies pagination using
pageandlimit. - Returns an object containing
data(array of records),total(total record count),page, andlimit. - Uses Drizzle ORM for database interactions.
- Validates the
- This dynamic GET endpoint retrieves a paginated and filtered list of records for a specified
Count API (
/api/admin/count/[tableName]/[columnName].get.ts)- This dynamic GET endpoint retrieves the count of distinct values for a specified
columnNamewithin a giventableName, optionally filtered. - Path Parameters:
tableName(string): The name of the database table.columnName(string): The name of the column to count distinct values from.
- Query Parameters:
filter(string, optional): A JSON string representing an array of filter conditions, similar to the List API.
- Functionality:
- Validates
tableNameandcolumnName. - Parses and applies
filterquery parameters. - Returns an array of objects, each containing a distinct
columnvalue and itscount. - Useful for generating statistics or populating filter options (e.g., checkboxes with counts).
- Validates
- This dynamic GET endpoint retrieves the count of distinct values for a specified
This combination of a flexible frontend component and robust backend APIs provides a powerful system for data management in the admin panel.