List
The <smart-list> component renders a list of entities. It is a wrapper that dispatches to one of three built-in child components based on options.mode or HardwareService.isMobile auto-detection. Each mode's child can be replaced via LIST_MODE_COMPONENTS_TOKEN, which provides a partial override map — any mode you specify replaces the default child; any mode you omit falls back to the built-in.
Usage
<smart-list [options]="options" />
@if (selected(); as member) {
<p>Selected member: {{ member.firstName }} {{ member.lastName }}</p>
}
The preview renders the code above in an application that registers every preset (provideSmartPresets(), see Installation) and the English translations; without the presets, a component that has one renders its standard implementation instead, for most components unstyled markup.
Components
ListComponent (<smart-list>)
Main wrapper. Resolves the list fields of options.type (the @Field({ list }) fields, sorted by list.order), reads options.mode (or falls back to HardwareService.isMobile for auto mobile detection) and renders the mode component via NgComponentOutlet, passing the options with the resolved fields and the class. Below the mode component it renders <smart-loader> while provider.loading() is true and a "no results" heading (noResults translation) for an empty list.
ListDesktopComponent (<smart-list-desktop>)
Default desktop implementation. A CDK table with a sticky header row, one column per list field, plus the multi-select checkbox column (select: 'multi'), the details column (details), the remove column (remove) and the item action column (item); the top component factory above it and <smart-paging> below it when pagination.mode is PaginationMode.singlePage. With sort the field headers are sort buttons (see Sorting).
ListMobileComponent (<smart-list-mobile>)
Default mobile implementation. Renders a <ul role="list"> with flex rows, one paragraph per cell, plus the details, remove and item action buttons; the top component factory above it and <smart-paging> below it (PaginationMode.singlePage).
ListMasonryGridComponent (<smart-list-masonry-grid>)
Default masonry-grid implementation. Renders a grid of tiles with the item's image (the model's first FieldType.image field) over its other cells; the top component factory above it and <smart-paging> below it (PaginationMode.singlePage). Its only row action is the details button (details).
ListBaseComponent (abstract)
Abstract base directive. Extend it to build custom list implementations for any mode. It reads options() (an IListInternalOptions<T>: the IListOptions plus the resolved fields) and exposes:
keys— string array of visible column keys (the list fields the user may see,list.permissions, withdynamicfields expanded), set byinitKeys()list—Signal<CdkTableDataSourceInput<T> | null>: the provider's rows without the ones removed in this listloading—Signal<boolean>from the providerpage,totalPages—Signal<number | null>from the pagination optionstype— the model class,sort,selectMode(options.sort ?? {},options.select)sortable—Signal<boolean>,truewithoptions.sort;activeSort—WritableSignal<IListSortState | null>, the sort the headers show (sort.default/sort.defaultDescat first, then the last header clicked; it starts over whenoptions.sortchanges)itemHandler— resolved item navigation (Router.navigate([routingPrefix, id])) or select handler,nullwithoutitemremoveHandler— confirms withAlertService(OBJECT.confirmDelete) and callsremove.provider.invoke(id),nullwithoutremove;checkRemoveHandlerisremove.provider.checkdetailsHandler— opens the details of an item in a modal (openDetails(item)),nullwithoutdetailsdetailsComponent,detailsComponentProps,select,unselect— set fromdetails: the customdetails.component(elseundefined, andDetailsPageopens), theIDetailsOptionsit gets asvalue, and the provider'sgetData/clearDatainfiniteScroll—Signal<boolean>,truewithPaginationMode.infiniteScrollwhilepage() < totalPages();infiniteScrollAnchor— the view query of the#infiniteScrollAnchorelement the modes render after the itemsloadNextPage,loadPrevPage— the pagination loaders (they scroll the window),nullwithoutpaginationcellPipe—ICellPipe<T> | nullcssClass— string input (aliasclass), forwarded by<smart-list>
The resolved fields themselves are private; read options().fields in a subclass. provider is protected.
Methods:
initKeys()(protected) — populateskeysfrom the resolved fieldshandlePageChange(page: number)— callsloadNextPage()for a later page andloadPrevPage()for an earlier oneisSortable(key),sortBy(key),ariaSort(key),sortIndicator(key)— whether a header sorts (every field column withsort, not the__arraycolumns of adynamicfield), sort by it (callsprovider.getData({ offset: 0, sortBy, sortDesc })), itsaria-sort('ascending'/'descending'on the active header,nullotherwise) and its arrow (↑,↓,↕)openDetails(item)— clears the details provider (unselect()), opensdetailsComponent ?? DetailsPagein a'bottom'modal (a bottom sheet) throughshowDetailsModalwith{ value: detailsComponentProps }, then callsselect(item.id)
API
Inputs
| Input | Type | Default | Description |
|---|---|---|---|
options | InputSignal<IListOptions<T>> | required | Full list configuration |
class | InputSignal<string> | '' | External CSS classes, forwarded to the mode component (cssClass) |
IListOptions<T>
IListOptions property reference
| Property | Type | Default | Description |
|---|---|---|---|
provider | IListProvider<T> | required | Where the rows come from (list, loading signals) and the multi-selection callbacks. |
type | any | required | Model class decorated with @Model; its @Field({ list }) fields are the columns. |
mode | ListMode | - | Force a specific mode; omit to auto-detect via HardwareService.isMobile (mobile or desktop). |
pagination | IListPaginationOptions | - | Paging state and loaders: <smart-paging> for PaginationMode.singlePage, the next page on scroll for PaginationMode.infiniteScroll (see Infinite scroll). |
cellPipe | ICellPipe<T> | - | Formats cells: transform(item, key, translate?) returns the cell text (rendered as HTML through Angular's sanitiser). |
componentFactories | IListComponentFactories<T> | - | top: a component created above the rows. |
sort | boolean | { default?: string; defaultDesc?: boolean } | - | Makes the field headers of the desktop modes sort buttons; default / defaultDesc is the sort they show at first (see Sorting). |
details | boolean | { provider?: IDetailsProvider<T>; componentFactories?: IDetailsComponentFactories<T>; component?: Type<any> } | - | Adds a details action (show) to every item that opens component (DetailsPage by default) in a modal; requires a provider (else it throws). See Details. |
item | boolean | { options?: ItemOptions } | - | Adds the item action: { options: { routingPrefix, edit } } navigates to routingPrefix/id, { options: { select, edit } } calls select(id). Setting item without options throws. |
remove | boolean | { provider?: IRemoveProvider<T> } | - | Adds the remove action: an alert (OBJECT.confirmDelete), then provider.invoke(id); provider.check(item) hides it per row. |
select | 'multi' | - | Adds a checkbox column (desktop and desktop preset); changes go to provider.onChangeMultiSelected. |
presentation | { variant?: 'default' | 'striped' | 'bordered' | 'borderless'; hoverable?: boolean; header?: 'default' | 'muted' | 'none' } | {} | Desktop preset only: the table variant ('default'), hoverable rows and the header look ('default'). The standard components ignore it. |
IListProvider<T>
| Field | Type | Default | Description |
|---|---|---|---|
list | Signal<T[]> | required | The records to show. |
loading | Signal<boolean> | required | Shows the loader while true. |
getData | (filter: any) => void | required | Reads the data again with filter merged in; a sortable header calls it with { offset: 0, sortBy, sortDesc }. |
onChangeMultiSelected? | (list: T[]) => void | - | Called with the selected records when select: 'multi'. |
onCleanMultiSelected$? | Observable<void> | - | Clears the multi-selection whenever it emits. |
ListMode
ListMode is an enum: ListMode.mobile ('mobile'), ListMode.desktop ('desktop'), ListMode.masonryGrid ('masonryGrid').
IListPaginationOptions
| Field | Type | Default | Description |
|---|---|---|---|
mode? | PaginationMode | - | PaginationMode.singlePage renders <smart-paging>; PaginationMode.infiniteScroll loads the next page when the end of the items scrolls into view. |
limit | number | required | Page size, for the provider's owner; the list does not read it. |
loadNextPage | () => Promise<boolean> | required | Loads the next page. |
loadPrevPage | () => Promise<boolean> | required | Loads the previous page. |
page | Signal<number> | required | Current page. |
totalPages | Signal<number> | required | Number of pages. |
PaginationMode is an enum: PaginationMode.infiniteScroll ('infiniteScroll'), PaginationMode.singlePage ('singlePage').
ItemOptions, IRemoveProvider, IDetailsProvider
| Type | Fields |
|---|---|
IItemOptionsForPage | routingPrefix: string (the item URL is routingPrefix/id), edit: boolean (passed along) |
IItemOptionsForCustom | select: (id: string) => void (called instead of navigating), edit: boolean |
ItemOptions | IItemOptionsForPage | IItemOptionsForCustom |
IRemoveProvider<T> | invoke: (id: string) => void (after the confirmation), check?: (item: T) => boolean (hides the action per row) |
IDetailsProvider<T> | getData: (id: string) => void, clearData: () => void, item: Signal<T>, loading: Signal<boolean> |
ICellPipe<T> | transform(value: T, columnName: string, translate?: (val: string) => string): string |
IListComponentFactories<T> | top?: Type<any> |
IListSortState | key: string, desc: boolean (the sort a list shows) |
IListSortFilter | offset: 0, sortBy: string, sortDesc: boolean (what a sortable header passes to provider.getData) |
Sorting
With sort set (true, or { default?, defaultDesc? }), every field header of the desktop table (standard and preset) is a sort button with an arrow: ↕ on the headers that do not sort the list, ↑ / ↓ on the active one, which also carries aria-sort (ascending / descending). A click on another column sorts by it in ascending order, a click on the active column turns the direction around. The list does not sort the rows itself: it calls provider.getData({ offset: 0, sortBy, sortDesc }), and the provider reads its data again in that order, from the first page. The CRUD list page (@smartsoft001/crud-shell-angular) merges that filter into its ICrudFilter, so the request carries sort=<field> or sort=-<field>. The expanded columns of a dynamic field do not sort. The mobile and masonry modes have no headers, so they ignore sort.
sort.default and sort.defaultDesc only set the header the list shows at first; the provider loads its first data in that order on its own. The clicked sort stays while other options change, and starts over from sort.default when the sort option is a new object. The helpers behind it are exported: getListDefaultSort, getNextListSort, getListAriaSort, getListSortIndicator and isListSortableKey.
Details
With details: { provider }, every item gets a details action, labelled with the show translation (data-role="details"): a column of the desktop table and a button in the mobile rows and the masonry tiles (standard and presets). It clears the provider (clearData()), opens details.component, or DetailsPage by default, in a bottom sheet through ModalService (mode 'bottom', see angular-components-modal) with { value: detailsComponentProps }, and asks the provider for the item (getData(id)). detailsComponentProps is an IDetailsOptions: item and loading from the provider (signals, so the modal shows the item once it is loaded), type, the list's itemHandler and removeHandler and details.componentFactories. The browser's back button closes the modal. Without a provider, setting details throws Must set details provider.
Infinite scroll
With pagination.mode set to PaginationMode.infiniteScroll and page() < totalPages(), every mode renders an empty <div data-role="infinite-scroll" aria-hidden="true"> after its items and watches it with an IntersectionObserver. When it scrolls into view, the list calls pagination.loadNextPage() (never twice at the same time), and it watches the element again after every page, so a short page loads the next one at once. On the last page the element is gone. Without IntersectionObserver (server rendering) nothing loads. The provider appends the new rows to provider.list (the CRUD store does for a filter whose paginationMode is not singlePage). pagination.limit is not read by the list.
LIST_MODE_COMPONENTS_TOKEN
InjectionToken from @smartsoft001/angular that provides a Partial<Record<ListMode, Type<ListBaseComponent<any>>>> override map. Any mode key you include replaces the built-in default child for that mode; any mode key you omit continues to use the built-in default.
Preline mode presets
Every mode ships a Preline-styled preset alongside the default child:
| ListMode | Preset | Look |
|---|---|---|
desktop | ListDesktopPresetComponent | Preline table (smart-list-desktop-preset), styling via presentation |
mobile | ListMobilePresetComponent | Responsive card grid (smart-list-mobile-preset), image → card image |
masonryGrid | ListMasonryGridPresetComponent | Masonry card columns (smart-list-masonry-grid-preset), image → card |
Apply them by providing the ready-made map LIST_PRESET_MODE_COMPONENTS (it covers all three modes) for LIST_MODE_COMPONENTS_TOKEN, or with provideSmartPresets(), which provides it together with every other preset.
The desktop preset reads the optional IListOptions.presentation field (see the property reference above).
Notes:
presentationis consumed only by the desktop preset; the standard components ignore it.- The mobile preset maps fields onto card anatomy:
FieldType.image/logo→ card image, first non-image field → title, remaining fields → body text; the item action renders as the card's primary button (label i18n key:details). - The masonryGrid preset keeps the base masonry column algorithm and image mechanism (
NgOptimizedImagefrom the model's image field) and restyles items with the same card recipe as the mobile preset; like the standard masonry child, its only action is the details button. - The desktop preset styles its sort buttons with
getListDesktopSortButtonClasses()andgetListDesktopSortIndicatorClasses(). - Preline "Table with search" / "with pagination" / "selectable rows" variants are covered by the existing
searchbarfeature,smart-paging(PaginationMode.singlePage), andselect: 'multi'respectively — not bypresentation. Table caption/footer variants are not supported (no API channel inIListOptions).
Extending the base class
import {
ChangeDetectionStrategy,
Component,
computed,
signal,
ViewEncapsulation,
} from '@angular/core';
import {
IListOptions,
LIST_MODE_COMPONENTS_TOKEN,
ListBaseComponent,
ListComponent,
ListMode,
} from '@smartsoft001/angular';
import { Field, FieldType, Model } from '@smartsoft001/models';
// `<smart-list>` reads the columns off the model metadata, so only the fields
// marked `list: true` become keys of the rendered list.
@Model({})
export class DocsUser {
id = '';
@Field({ list: true, type: FieldType.text })
firstName = '';
@Field({ list: true, type: FieldType.email })
email = '';
@Field({ list: true, type: FieldType.text })
role = '';
}
/**
* A custom list built on `ListBaseComponent`.
*
* The base resolves `keys` from the model metadata, exposes the rows as the
* `list` signal and the busy flag as `loading`; the implementation only turns
* that into markup.
*/
@Component({
selector: 'docs-custom-list',
template: `
<table [class]="containerClasses()">
<thead>
<tr>
@for (key of keys; track key) {
<th class="docs-list__header">{{ key }}</th>
}
</tr>
</thead>
<tbody>
@for (row of rows(); track row.id) {
<tr class="docs-list__row">
@for (key of keys; track key) {
<td class="docs-list__cell">{{ cell(row, key) }}</td>
}
</tr>
}
</tbody>
</table>
`,
encapsulation: ViewEncapsulation.None,
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class CustomListComponent extends ListBaseComponent<DocsUser> {
// The class passed to `<smart-list>` arrives in the inherited `cssClass`
// input (alias `class`).
containerClasses = computed(() =>
['docs-list', this.cssClass()].filter(Boolean).join(' '),
);
// `list` is typed as a CDK table data source, which also covers observables
// and DataSource instances; this example only handles the plain array form.
rows = computed<DocsUser[]>(() => {
const value = this.list();
return Array.isArray(value) ? value : [];
});
cell(row: DocsUser, key: string): string {
return String((row as unknown as Record<string, unknown>)[key] ?? '');
}
}
/**
* The list wrapper resolves its body from a map of modes rather than from a
* single standard-component token, so the implementation is registered under
* the mode that `IListOptions.mode` asks for. The map is merged over the
* built-in one, so the other modes keep their own components.
*/
@Component({
selector: 'docs-list-custom-example',
changeDetection: ChangeDetectionStrategy.OnPush,
imports: [ListComponent],
providers: [
{
provide: LIST_MODE_COMPONENTS_TOKEN,
useValue: { [ListMode.desktop]: CustomListComponent },
},
],
template: `<smart-list [options]="options" />`,
})
export class ListCustomExampleComponent {
// A provider is the list's data source: the rows and the loading flag as
// signals, plus `getData` for the provider's owner (the list never calls
// it). A real application hands over an NgRx facade here instead of static
// rows.
options: IListOptions<DocsUser> = {
provider: {
list: signal<DocsUser[]>([
{ id: '1', firstName: 'Jan', email: 'jan@example.com', role: 'Admin' },
{
id: '2',
firstName: 'Anna',
email: 'anna@example.com',
role: 'User',
},
{
id: '3',
firstName: 'Piotr',
email: 'piotr@example.com',
role: 'User',
},
]),
loading: signal(false),
getData: () => undefined,
},
type: DocsUser,
mode: ListMode.desktop,
};
}
Source
The component lives in packages/shared/angular/src/lib/components/list and is documented for Claude Code by the angular-components-list skill.
SmartList renders records of a @Model class. Its columns are the model's fields marked @Field({ list: ... }), sorted by list.order; its rows come from options.provider.list, and provider.loading shows the loader (and suppresses the "no results" text). options.mode picks the layout: ListMode.desktop (a table, the default), ListMode.mobile (stacked rows) or ListMode.masonryGrid (image tiles). Row actions are opt-in: item adds a "go to item" action (navigate to routingPrefix + id through the navigation adapter, or call select(id)), remove a remove action confirmed with an alert, details a details action that opens the record in a modal, select: 'multi' a checkbox column. With sort the desktop headers are sort buttons. The list does not fetch: the provider's owner loads the data, also sorted (provider.getData) or by pages (CRUD screens wire all of this from a CrudFullConfig).
Usage
import { useMemo, useState } from 'react';
import { Field, FieldType, Model } from '@smartsoft001/models';
import {
IListOptions,
IListSortFilter,
ListMode,
SmartList,
} from '@smartsoft001/react';
@Model({})
class Member {
id = '';
@Field({ list: { order: 1 }, type: FieldType.text })
firstName = '';
@Field({ list: { order: 2 }, type: FieldType.text })
lastName = '';
@Field({ list: { order: 3 }, type: FieldType.email })
email = '';
}
const members: Member[] = [
{
id: '1',
firstName: 'Lindsay',
lastName: 'Walton',
email: 'lindsay.walton@example.com',
},
{
id: '2',
firstName: 'Courtney',
lastName: 'Henry',
email: 'courtney.henry@example.com',
},
{
id: '3',
firstName: 'Tom',
lastName: 'Cook',
email: 'tom.cook@example.com',
},
];
// Stands in for the server: the rows of `members` in the order asked for.
function sortMembers(key: string, desc: boolean): Member[] {
const field = key as keyof Member;
return [...members].sort(
(a, b) => a[field].localeCompare(b[field]) * (desc ? -1 : 1),
);
}
// The headers sort the list, starting from the last name. A constant, so the
// list keeps the sort a header click chose.
const SORT = { default: 'lastName' };
export function ListUsageExample() {
const [selected, setSelected] = useState<Member | null>(null);
const [list, setList] = useState(() => sortMembers('lastName', false));
// The provider is the data source; in an app it usually comes from a store.
const options = useMemo<IListOptions<Member>>(
() => ({
type: Member,
mode: ListMode.desktop,
provider: {
list,
loading: false,
// A click on a column header asks for the rows sorted by that column.
getData: ({ sortBy, sortDesc }: IListSortFilter) =>
setList(sortMembers(sortBy, sortDesc)),
},
sort: SORT,
// The item action of a row calls `select` with the row's id.
item: {
options: {
edit: false,
select: (id) =>
setSelected(members.find((member) => member.id === id) ?? null),
},
},
}),
[list],
);
return (
<>
<SmartList options={options} />
{selected && (
<p>
Selected member: {selected.firstName} {selected.lastName}
</p>
)}
</>
);
}
The preview renders the code above in an application that registers every preset (SMART_PRESET_COMPONENTS on SmartProvider, see Installation) and the English translations; without the presets, a component that has one renders its standard implementation instead, for most components unstyled markup.
Exports
All from @smartsoft001/react.
| Export | Kind | What it is |
|---|---|---|
SmartList | component | Resolves the list fields of options.type (the fields with list options, sorted by list.order) and renders the implementation of options.mode (desktop by default): the one registered in listModeComponents on SmartProvider (e.g. LIST_PRESET_MODE_COMPONENTS), else SmartListDesktop / SmartListMobile / SmartListMasonryGrid. |
SmartListDesktop | component | The desktop list: a table with one column per list field, plus the multi-select, details, remove and item columns, the top component factory above it and the paging below it (PaginationMode.singlePage); with options.sort the field headers are sort buttons. |
SmartListDesktopPreset | component | Preline-styled desktop list variation. |
SmartListMasonryGrid | component | The masonry-grid list: a grid of tiles with the item's image (the model's first image field, lazy loaded) over its non-image cells, the top component factory above it and the paging below it (PaginationMode.singlePage); with options.details every tile gets a details button. |
SmartListMasonryGridPreset | component | Preline-styled masonry-grid list variation: keeps the masonry column layout and renders every item as a Preline card, the image on a rounded top, the first non-image column as the title and the others as text. |
SmartListMobile | component | The mobile list: a stacked list with one paragraph per cell and the details / remove / item buttons, the top component factory above it and the paging below it (PaginationMode.singlePage). |
SmartListMobilePreset | component | Preline-styled mobile list variation: a responsive grid of cards. |
useListFileUrl | hook | The download URL of an image cell's attachment ('' without a file service). |
useList | hook | The behaviour every list mode shares: the column keys (permissions via useAuthService(), dynamic __array columns), the provider list and loading, the sort options, the remove flow (a confirm alert, then remove.provider.invoke(id)), item navigation (useNavigation().navigate(routingPrefix + id) or item.options.select), the details provider (select / unselect, detailsComponent and its props, detailsHandler), the sort (sortBy, activeSort) and the pagination (loadNextPage / loadPrevPage, handlePageChange, infinite scroll). |
SmartListDetailsModal | component | What the details action opens through ModalService: the details component (SmartDetailsPage by default) with the list's current IDetailsOptions as value, read from a store the list keeps up to date. |
getListDefaultSort, getNextListSort, getListAriaSort, getListSortIndicator, isListSortableKey | function | The sort helpers of useList: the start sort of a sort option, the sort after a header click, the aria-sort and the arrow of a header, whether a column sorts. |
isListImageKey | function | Whether a column is an image field of the model. |
getListTitleKey | function | The first non-image column (the card title of the mobile and masonry presets). |
LIST_PRESET_MODE_COMPONENTS | const | Preline-styled list mode presets, keyed by ListMode. |
useListDesktop | hook | The desktop table logic: useList plus the table columns (desktopKeys: selectMulti, the keys, detailsAction, removeAction, itemAction), the multi selection reported through provider.onChangeMultiSelected and cleared by provider.onCleanMultiSelected$, and the top component factory. |
useListMasonryGrid | hook | The masonry-grid logic: useList plus listWithImages, every item paired with the value of the model's first image field. |
LIST_DESKTOP_STICKY_HEADER_STYLE | const | The inline style of the sticky header cells of SmartListDesktop (position: sticky, top: 0). |
The preset's class helpers (getListDesktopContainerClasses, getListDesktopTableClasses, getListDesktopHeaderRowClasses, getListDesktopHeaderCellClasses, getListDesktopSortButtonClasses, getListDesktopSortIndicatorClasses, getListDesktopRowClasses, getListDesktopCellClasses) are exported too, for a custom implementation that wants the preset look.
Props and Types
SmartListProps<T extends IEntity<string>>
Props of <SmartList>.
| Prop | Type | Default | Description |
|---|---|---|---|
options | IListOptions<T> | required | The provider, the model type, the mode and the actions. |
className? | string | '' | Passed to the mode component (its container). |
SmartListModeProps<T extends IEntity<string>>
Props of a list mode implementation (SmartListDesktop, SmartListMobile, SmartListMasonryGrid, their presets, or one registered through listModeComponents / components.list on SmartProvider). SmartList passes the options with the list fields of the model already resolved.
| Prop | Type | Default | Description |
|---|---|---|---|
options | IListInternalOptions<T> | required | The list options with the resolved fields. |
className? | string | — | The className of SmartList. |
IListOptions<T>
| Field | Type | Default | Description |
|---|---|---|---|
provider | IListProvider<T> | required | Where the rows come from (list, loading), and the multi-selection callbacks. |
type | any | required | The @Model class whose list fields are the columns. |
mode? | ListMode | — | ListMode.desktop (default), ListMode.mobile or ListMode.masonryGrid. |
pagination? | IListPaginationOptions | — | Paging state and loaders: with PaginationMode.singlePage the modes render the pager below the rows, with PaginationMode.infiniteScroll they load the next page when the end of the rows scrolls into view. |
cellPipe? | ICellPipe<T> | — | Formats cells: transform(item, key, translate?) returns text (sanitised) or trustHtml(html). |
componentFactories? | IListComponentFactories<T> | — | top: a component rendered above the rows. |
sort? | | boolean | { default?: string; defaultDesc?: boolean; } | — | Makes the field headers of the desktop modes sort buttons; default / defaultDesc is the sort they show at first (see Sorting). |
details? | | boolean | { provider?: IDetailsProvider<T>; componentFactories?: IDetailsComponentFactories<T>; component?: ComponentType<any>; } | — | Adds a details action (show) to every item that opens component (SmartDetailsPage by default) in a modal; requires a provider (IDetailsProvider). See Details. |
item? | | boolean | { options?: ItemOptions; } | — | Adds the item action: { options: { routingPrefix, edit } } navigates to routingPrefix + id, { options: { select, edit } } calls select(id). Setting item without options throws. |
remove? | | boolean | { provider?: IRemoveProvider<T>; } | — | Adds the remove action: an alert (OBJECT.confirmDelete) then provider.invoke(id); provider.check(item) hides it per row. |
select? | 'multi' | — | 'multi' adds a checkbox column (desktop); changes go to provider.onChangeMultiSelected. |
presentation? | { variant?: 'default' | 'striped' | 'bordered' | 'borderless'; hoverable?: boolean; header?: 'default' | 'muted' | 'none'; } | {} | Desktop preset look: variant (default, striped, bordered, borderless), hoverable, header (default, muted, none). |
IListInternalOptions<T>
What mode components receive: IListOptions plus the resolved fields. Extends IListOptions<T>.
| Field | Type | Default | Description |
|---|---|---|---|
fields? | Array<{ key: string; options: IFieldOptions }> | — | The list fields of the model, sorted by list.order. |
IListPaginationOptions
| Field | Type | Default | Description |
|---|---|---|---|
mode? | PaginationMode | — | PaginationMode.singlePage (pager) or PaginationMode.infiniteScroll. |
limit | number | required | Page size, for the provider's owner; the list does not read it. |
loadNextPage | () => Promise<boolean> | required | Loads the next page; resolves whether there is a further one. |
loadPrevPage | () => Promise<boolean> | required | Loads the previous page; resolves whether there is a further one. |
page | number | required | Current page. |
totalPages | number | required | Number of pages. |
IListProvider<T>
| Field | Type | Default | Description |
|---|---|---|---|
getData | (filter: any) => void | required | Reads the data again with filter merged in; a sortable header calls it with { offset: 0, sortBy, sortDesc }. |
onChangeMultiSelected? | (list: Array<T>) => void | — | Called with the selected records when select: 'multi'. |
onCleanMultiSelected$? | SmartSubscribable<void> | — | Clears the multi-selection whenever it emits. |
list | T[] | required | The records to show. |
loading | boolean | required | Shows the loader while true. |
ICellPipe<T>
Formats a cell value.
| Field | Type | Default | Description |
|---|---|---|---|
transform | (value: T, columnName: string, translate?: (val: string) => string) => string | SmartTrustedHtml | required | The text of a cell. Markup in it is sanitised before it is rendered; return trustHtml(html) to render markup you vouch for as is. |
IListComponentFactories<T>
| Field | Type | Default | Description |
|---|---|---|---|
top? | ComponentType<any> | — | Rendered above the rows (no props). |
IDetailsProvider<T>
The record shown in a details view of the list.
| Field | Type | Default | Description |
|---|---|---|---|
getData | (id: string) => void | required | Loads the record of an id (useList().select). |
clearData | () => void | required | Clears it (useList().unselect). |
item | T | null | undefined | required | The loaded record. |
loading | boolean | required | Whether it is loading. |
IDetailsComponentFactories<T>
| Field | Type | Default | Description |
|---|---|---|---|
top? | ComponentType<any> | — | Rendered above the details. |
bottom? | ComponentType<any> | — | Rendered below the details. |
IRemoveProvider<T>
| Field | Type | Default | Description |
|---|---|---|---|
invoke | (id: string) => void | required | Removes the record of an id (after the confirmation). |
check? | (item: T) => boolean | — | Whether a record can be removed (hides the action per row). |
SmartSubscribable<T>
Anything with a subscribe(listener) that returns an unsubscribe() handle, e.g. a SmartEmitter or an observable.
| Field | Type | Default | Description |
|---|---|---|---|
subscribe | (listener: (value: T) => void) => { unsubscribe(): void } | required | Subscribes; returns { unsubscribe() }. |
IItemOptionsForPage
| Field | Type | Default | Description |
|---|---|---|---|
routingPrefix | string | required | The item URL is routingPrefix + id (one / between them). |
edit | boolean | required | Whether the target opens for editing (passed along). |
IItemOptionsForCustom
| Field | Type | Default | Description |
|---|---|---|---|
select | (id: string) => void | required | Called with the id instead of navigating. |
edit | boolean | required | Whether the target opens for editing (passed along). |
IListSortState and IListSortFilter
| Type | Fields |
|---|---|
IListSortState | key: string, desc: boolean: the sort a list shows (useList().activeSort). |
IListSortFilter | offset: 0, sortBy: string, sortDesc: boolean: what a header passes to getData. |
Related types
ListMode(enum):mobile = 'mobile', desktop = 'desktop', masonryGrid = 'masonryGrid'— The list layouts.ItemOptions:IItemOptionsForPage \| IItemOptionsForCustom— Navigate by URL, or callselect(id).PaginationMode(enum):infiniteScroll = 'infiniteScroll', singlePage = 'singlePage'— Pager or infinite scroll.
Columns from the model
list: trueorlist: { order?, permissions?, filter?, dynamic? }puts the field in the list;ordersorts the columns.list.permissions: the column is left out when the user has none of them.- Header labels come from the label provider, or
MODEL.<key>translated; cell values from the cell pipe, or the value, translated and sanitised. image/logofields render as images (the first image field is the masonry tile image).
Sorting
With sort set (true, or { default?, defaultDesc? }), every field header of SmartListDesktop and SmartListDesktopPreset is a sort button with an arrow: ↕ on the headers that do not sort the list, ↑ / ↓ on the active one, which also carries aria-sort (ascending / descending). A click on another column sorts by it in ascending order, a click on the active column turns the direction around. The list does not sort the rows itself: it calls provider.getData({ offset: 0, sortBy, sortDesc }) and the provider loads the rows in that order, from the first page. The CRUD list page (@smartsoft001/crud-shell-react) merges that filter into its ICrudFilter and passes the filter's sort back as sort. The expanded columns of a dynamic field do not sort; the mobile and masonry modes have no headers.
sort.default and sort.defaultDesc only set the header shown at first. The clicked sort stays while other options change and starts over from sort.default when sort is a new object, so keep sort stable (a constant or a memoised value).
Details
With details: { provider }, every item gets a details action, labelled with the show translation (data-role="details"): a column of the desktop table and a button in the mobile rows and the masonry tiles (standard and presets). useList().detailsHandler(item) clears the provider (clearData()), opens SmartListDetailsModal in a bottom sheet through ModalService (mode 'bottom', rendered by SmartModalHost, see react-components-overlays) around details.component, or SmartDetailsPage by default, and asks the provider for the item (getData(id)). The modal reads detailsComponentProps (IDetailsOptions: item and loading from the provider, type, the list's itemHandler / removeHandler, details.componentFactories) from a store the list updates, so it shows the item once the provider has loaded it. Without a provider, setting details throws Must set details provider.
Infinite scroll
With pagination.mode set to PaginationMode.infiniteScroll and page < totalPages, every mode renders an empty <div data-role="infinite-scroll" aria-hidden="true"> after its items, watched by an IntersectionObserver. When it scrolls into view the list calls pagination.loadNextPage() (never twice at the same time), and it watches it again after every page. On the last page the element is gone; without IntersectionObserver (server rendering) nothing loads. pagination.limit is not read by the list.
Replacing the Implementation
- Per mode:
listModeComponentsonSmartProvidermaps aListModeto a component takingSmartListModeProps(merged overSmartListDesktop/SmartListMobile/SmartListMasonryGrid).LIST_PRESET_MODE_COMPONENTSregisters the Preline-styledSmartListDesktopPreset,SmartListMobilePresetandSmartListMasonryGridPreset. - Every mode at once: a component registered under the
'list'key ofcomponentsreplaces the list for every mode.
SMART_PRESET_COMPONENTS registers the mode presets with every other preset. SmartList keeps rendering the loader and the "no results" text (noResults translation) below whatever mode component is used.
Hooks
useListFileUrl
The URL of an image cell: the download URL of an attachment ({ id }), '' without a file service.
useList
The behaviour every list mode shares: the column keys (permissions via useAuthService(), dynamic __array columns), the provider list and loading, the sort options, the remove flow (a confirm alert, then remove.provider.invoke(id)), item navigation (useNavigation().navigate(routingPrefix + id) or item.options.select), the details provider (select / unselect, detailsComponent and its props) and the pagination (loadNextPage / loadPrevPage, handlePageChange). With pagination.mode === PaginationMode.infiniteScroll and a next page, infiniteScroll is true: render an element with infiniteScrollRef after the items, and the next page loads when it scrolls into view.
| Returns | Type | Description |
|---|---|---|
fields | { key: string; options: IFieldOptions; }[] | options.fields. |
provider | IListProvider<T> | options.provider. |
sort | boolean | { default?: string; defaultDesc?: boolean; } | options.sort ?? {}. |
cellPipe | ICellPipe<T> | null | options.cellPipe, null without one. |
selectMode | "multi" | undefined | options.select. |
type | any | options.type. |
keys | string[] | The column keys: the list fields the user may see (list.permissions), with dynamic columns expanded. |
list | T[] | null | provider.list without the rows removed in this list. |
loading | boolean | provider.loading. |
removed | Set<string> | Ids hidden after a remove. |
removeHandler | ((item: T) => void) | null | Confirms and removes a record (null without remove). |
checkRemoveHandler | ((item: T) => boolean) | undefined | remove.provider.check. |
itemHandler | ((id: string) => void) | null | Navigates to / selects an id (null without item). |
detailsComponent | ComponentType<any> | null | details.component, null without it (the details action then opens SmartDetailsPage). |
detailsComponentProps | IDetailsOptions<T> | null | The IDetailsOptions the details component gets as value, null without details. |
detailsHandler | ((item: T) => void) | null | Opens the details of an item in a modal (null without details). |
select | ((id: string) => void) | undefined | details.provider.getData. |
unselect | (() => void) | undefined | details.provider.clearData. |
detailsButtonOptions | IButtonOptions | IButtonOptions that close the details (unselect). |
loadNextPage | (() => Promise<void>) | null | Loads the next page and scrolls to the top (null without pagination). |
loadPrevPage | (() => Promise<void>) | null | Loads the previous page and scrolls to the top. |
page | number | null | pagination.page. |
totalPages | number | null | pagination.totalPages. |
handlePageChange | (nextPage: number) => void | Moves to a page through the loaders (for SmartPaging's onPageChange). |
infiniteScroll | boolean | true with PaginationMode.infiniteScroll and a next page. |
infiniteScrollRef | RefObject<HTMLDivElement | null> | Attach to an element after the rows; the next page loads when it scrolls into view. |
sortable | boolean | true with options.sort. |
activeSort | IListSortState | null | The sort the headers show. |
isSortable | (key: string) => boolean | Whether the header of a column sorts. |
sortBy | (key: string) => void | Sorts by a column through provider.getData({ offset: 0, sortBy, sortDesc }). |
getAriaSort | (key: string) => 'ascending' | 'descending' | null | The aria-sort of a header (only the active one has it). |
getSortIndicator | (key: string) => string | The arrow of a header: ↑, ↓, or ↕ when it is not active. |
import { useMemo } from 'react';
import { Field, FieldType, Model } from '@smartsoft001/models';
import {
IListOptions,
ListMode,
SmartList,
SmartListModeProps,
SmartProvider,
useList,
} from '@smartsoft001/react';
// `SmartList` reads the columns off the model metadata, so only the fields
// marked `list: true` become keys of the rendered list.
@Model({})
export class DocsUser {
id = '';
@Field({ list: true, type: FieldType.text })
firstName = '';
@Field({ list: true, type: FieldType.email })
email = '';
@Field({ list: true, type: FieldType.text })
role = '';
}
/**
* A custom list mode built on `useList`: the hook resolves the column `keys`
* from the model metadata and exposes the provider's rows as `list`; the
* implementation only turns that into markup.
*/
export function CustomList(props: SmartListModeProps<DocsUser>) {
const { keys, list } = useList(props);
return (
<table className={['docs-list', props.className].filter(Boolean).join(' ')}>
<thead>
<tr>
{keys.map((key) => (
<th key={key} className="docs-list__header">
{key}
</th>
))}
</tr>
</thead>
<tbody>
{(list ?? []).map((row) => (
<tr key={row.id} className="docs-list__row">
{keys.map((key) => (
<td key={key} className="docs-list__cell">
{String(row[key as keyof DocsUser] ?? '')}
</td>
))}
</tr>
))}
</tbody>
</table>
);
}
// The list resolves its body from a map of modes, so the implementation is
// registered under the mode that `options.mode` asks for. The map is merged
// over the built-in one, so the other modes keep their own components.
const listModeComponents = { [ListMode.desktop]: CustomList };
const users: DocsUser[] = [
{ id: '1', firstName: 'Jan', email: 'jan@example.com', role: 'Admin' },
{ id: '2', firstName: 'Anna', email: 'anna@example.com', role: 'User' },
{ id: '3', firstName: 'Piotr', email: 'piotr@example.com', role: 'User' },
];
export function ListCustomExample() {
// The provider is the list's data source; a real application hands over
// the rows and the loading flag of its store here.
const options = useMemo<IListOptions<DocsUser>>(
() => ({
type: DocsUser,
mode: ListMode.desktop,
provider: { list: users, loading: false, getData: () => undefined },
}),
[],
);
return (
<SmartProvider listModeComponents={listModeComponents}>
<SmartList options={options} />
</SmartProvider>
);
}
Register it for one mode with listModeComponents={{ [ListMode.desktop]: CustomList }}, or for every mode with components={{ list: CustomList }}.
Styling
SmartListDesktopis a table with a sticky header (LIST_DESKTOP_STICKY_HEADER_STYLE); the presets carry the Preline looks withsmart:dark:variants, the desktop one driven byoptions.presentation.
Source
The component lives in packages/shared/react/src/lib/components/list and is documented for Claude Code by the react-components-list skill.