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, with dynamic fields expanded), set by initKeys()
  • list — Signal<CdkTableDataSourceInput<T> | null>: the provider's rows without the ones removed in this list
  • loading — Signal<boolean> from the provider
  • page, totalPages — Signal<number | null> from the pagination options
  • type — the model class, sort, selectMode (options.sort ?? {}, options.select)
  • sortable — Signal<boolean>, true with options.sort; activeSort — WritableSignal<IListSortState | null>, the sort the headers show (sort.default / sort.defaultDesc at first, then the last header clicked; it starts over when options.sort changes)
  • itemHandler — resolved item navigation (Router.navigate([routingPrefix, id])) or select handler, null without item
  • removeHandler — confirms with AlertService (OBJECT.confirmDelete) and calls remove.provider.invoke(id), null without remove; checkRemoveHandler is remove.provider.check
  • detailsHandler — opens the details of an item in a modal (openDetails(item)), null without details
  • detailsComponent, detailsComponentProps, select, unselect — set from details: the custom details.component (else undefined, and DetailsPage opens), the IDetailsOptions it gets as value, and the provider's getData / clearData
  • infiniteScroll — Signal<boolean>, true with PaginationMode.infiniteScroll while page() < totalPages(); infiniteScrollAnchor — the view query of the #infiniteScrollAnchor element the modes render after the items
  • loadNextPage, loadPrevPage — the pagination loaders (they scroll the window), null without pagination
  • cellPipe — ICellPipe<T> | null
  • cssClass — string input (alias class), forwarded by <smart-list>

The resolved fields themselves are private; read options().fields in a subclass. provider is protected.

Methods:

  • initKeys() (protected) — populates keys from the resolved fields
  • handlePageChange(page: number) — calls loadNextPage() for a later page and loadPrevPage() for an earlier one
  • isSortable(key), sortBy(key), ariaSort(key), sortIndicator(key) — whether a header sorts (every field column with sort, not the __array columns of a dynamic field), sort by it (calls provider.getData({ offset: 0, sortBy, sortDesc })), its aria-sort ('ascending' / 'descending' on the active header, null otherwise) and its arrow (↑, ↓, ↕)
  • openDetails(item) — clears the details provider (unselect()), opens detailsComponent ?? DetailsPage in a 'bottom' modal (a bottom sheet) through showDetailsModal with { value: detailsComponentProps }, then calls select(item.id)

API

Inputs

InputTypeDefaultDescription
optionsInputSignal<IListOptions<T>>requiredFull list configuration
classInputSignal<string>''External CSS classes, forwarded to the mode component (cssClass)

IListOptions<T>

IListOptions property reference

PropertyTypeDefaultDescription
providerIListProvider<T>requiredWhere the rows come from (list, loading signals) and the multi-selection callbacks.
typeanyrequiredModel class decorated with @Model; its @Field({ list }) fields are the columns.
modeListMode-Force a specific mode; omit to auto-detect via HardwareService.isMobile (mobile or desktop).
paginationIListPaginationOptions-Paging state and loaders: <smart-paging> for PaginationMode.singlePage, the next page on scroll for PaginationMode.infiniteScroll (see Infinite scroll).
cellPipeICellPipe<T>-Formats cells: transform(item, key, translate?) returns the cell text (rendered as HTML through Angular's sanitiser).
componentFactoriesIListComponentFactories<T>-top: a component created above the rows.
sortboolean | { 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).
detailsboolean | { 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.
itemboolean | { options?: ItemOptions }-Adds the item action: { options: { routingPrefix, edit } } navigates to routingPrefix/id, { options: { select, edit } } calls select(id). Setting item without options throws.
removeboolean | { 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>

FieldTypeDefaultDescription
listSignal<T[]>requiredThe records to show.
loadingSignal<boolean>requiredShows the loader while true.
getData(filter: any) => voidrequiredReads 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

FieldTypeDefaultDescription
mode?PaginationMode-PaginationMode.singlePage renders <smart-paging>; PaginationMode.infiniteScroll loads the next page when the end of the items scrolls into view.
limitnumberrequiredPage size, for the provider's owner; the list does not read it.
loadNextPage() => Promise<boolean>requiredLoads the next page.
loadPrevPage() => Promise<boolean>requiredLoads the previous page.
pageSignal<number>requiredCurrent page.
totalPagesSignal<number>requiredNumber of pages.

PaginationMode is an enum: PaginationMode.infiniteScroll ('infiniteScroll'), PaginationMode.singlePage ('singlePage').

ItemOptions, IRemoveProvider, IDetailsProvider

TypeFields
IItemOptionsForPageroutingPrefix: string (the item URL is routingPrefix/id), edit: boolean (passed along)
IItemOptionsForCustomselect: (id: string) => void (called instead of navigating), edit: boolean
ItemOptionsIItemOptionsForPage | 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>
IListSortStatekey: string, desc: boolean (the sort a list shows)
IListSortFilteroffset: 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:

ListModePresetLook
desktopListDesktopPresetComponentPreline table (smart-list-desktop-preset), styling via presentation
mobileListMobilePresetComponentResponsive card grid (smart-list-mobile-preset), image → card image
masonryGridListMasonryGridPresetComponentMasonry 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:

  • presentation is 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 (NgOptimizedImage from 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() and getListDesktopSortIndicatorClasses().
  • Preline "Table with search" / "with pagination" / "selectable rows" variants are covered by the existing searchbar feature, smart-paging (PaginationMode.singlePage), and select: 'multi' respectively — not by presentation. Table caption/footer variants are not supported (no API channel in IListOptions).

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.

ExportKindWhat it is
SmartListcomponentResolves 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.
SmartListDesktopcomponentThe 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.
SmartListDesktopPresetcomponentPreline-styled desktop list variation.
SmartListMasonryGridcomponentThe 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.
SmartListMasonryGridPresetcomponentPreline-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.
SmartListMobilecomponentThe 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).
SmartListMobilePresetcomponentPreline-styled mobile list variation: a responsive grid of cards.
useListFileUrlhookThe download URL of an image cell's attachment ('' without a file service).
useListhookThe 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).
SmartListDetailsModalcomponentWhat 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, isListSortableKeyfunctionThe 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.
isListImageKeyfunctionWhether a column is an image field of the model.
getListTitleKeyfunctionThe first non-image column (the card title of the mobile and masonry presets).
LIST_PRESET_MODE_COMPONENTSconstPreline-styled list mode presets, keyed by ListMode.
useListDesktophookThe 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.
useListMasonryGridhookThe masonry-grid logic: useList plus listWithImages, every item paired with the value of the model's first image field.
LIST_DESKTOP_STICKY_HEADER_STYLEconstThe 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>.

PropTypeDefaultDescription
optionsIListOptions<T>requiredThe 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.

PropTypeDefaultDescription
optionsIListInternalOptions<T>requiredThe list options with the resolved fields.
className?string—The className of SmartList.

IListOptions<T>

FieldTypeDefaultDescription
providerIListProvider<T>requiredWhere the rows come from (list, loading), and the multi-selection callbacks.
typeanyrequiredThe @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>.

FieldTypeDefaultDescription
fields?Array<{ key: string; options: IFieldOptions }>—The list fields of the model, sorted by list.order.

IListPaginationOptions

FieldTypeDefaultDescription
mode?PaginationMode—PaginationMode.singlePage (pager) or PaginationMode.infiniteScroll.
limitnumberrequiredPage size, for the provider's owner; the list does not read it.
loadNextPage() => Promise<boolean>requiredLoads the next page; resolves whether there is a further one.
loadPrevPage() => Promise<boolean>requiredLoads the previous page; resolves whether there is a further one.
pagenumberrequiredCurrent page.
totalPagesnumberrequiredNumber of pages.

IListProvider<T>

FieldTypeDefaultDescription
getData(filter: any) => voidrequiredReads 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.
listT[]requiredThe records to show.
loadingbooleanrequiredShows the loader while true.

ICellPipe<T>

Formats a cell value.

FieldTypeDefaultDescription
transform(value: T, columnName: string, translate?: (val: string) => string) => string | SmartTrustedHtmlrequiredThe 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>

FieldTypeDefaultDescription
top?ComponentType<any>—Rendered above the rows (no props).

IDetailsProvider<T>

The record shown in a details view of the list.

FieldTypeDefaultDescription
getData(id: string) => voidrequiredLoads the record of an id (useList().select).
clearData() => voidrequiredClears it (useList().unselect).
itemT | null | undefinedrequiredThe loaded record.
loadingbooleanrequiredWhether it is loading.

IDetailsComponentFactories<T>

FieldTypeDefaultDescription
top?ComponentType<any>—Rendered above the details.
bottom?ComponentType<any>—Rendered below the details.

IRemoveProvider<T>

FieldTypeDefaultDescription
invoke(id: string) => voidrequiredRemoves 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.

FieldTypeDefaultDescription
subscribe(listener: (value: T) => void) => { unsubscribe(): void }requiredSubscribes; returns { unsubscribe() }.

IItemOptionsForPage

FieldTypeDefaultDescription
routingPrefixstringrequiredThe item URL is routingPrefix + id (one / between them).
editbooleanrequiredWhether the target opens for editing (passed along).

IItemOptionsForCustom

FieldTypeDefaultDescription
select(id: string) => voidrequiredCalled with the id instead of navigating.
editbooleanrequiredWhether the target opens for editing (passed along).

IListSortState and IListSortFilter

TypeFields
IListSortStatekey: string, desc: boolean: the sort a list shows (useList().activeSort).
IListSortFilteroffset: 0, sortBy: string, sortDesc: boolean: what a header passes to getData.
  • ListMode (enum): mobile = 'mobile', desktop = 'desktop', masonryGrid = 'masonryGrid' — The list layouts.
  • ItemOptions: IItemOptionsForPage \| IItemOptionsForCustom — Navigate by URL, or call select(id).
  • PaginationMode (enum): infiniteScroll = 'infiniteScroll', singlePage = 'singlePage' — Pager or infinite scroll.

Columns from the model

  • list: true or list: { order?, permissions?, filter?, dynamic? } puts the field in the list; order sorts 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 / logo fields 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: listModeComponents on SmartProvider maps a ListMode to a component taking SmartListModeProps (merged over SmartListDesktop / SmartListMobile / SmartListMasonryGrid). LIST_PRESET_MODE_COMPONENTS registers the Preline-styled SmartListDesktopPreset, SmartListMobilePreset and SmartListMasonryGridPreset.
  • Every mode at once: a component registered under the 'list' key of components replaces 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.

ReturnsTypeDescription
fields{ key: string; options: IFieldOptions; }[]options.fields.
providerIListProvider<T>options.provider.
sortboolean | { default?: string; defaultDesc?: boolean; }options.sort ?? {}.
cellPipeICellPipe<T> | nulloptions.cellPipe, null without one.
selectMode"multi" | undefinedoptions.select.
typeanyoptions.type.
keysstring[]The column keys: the list fields the user may see (list.permissions), with dynamic columns expanded.
listT[] | nullprovider.list without the rows removed in this list.
loadingbooleanprovider.loading.
removedSet<string>Ids hidden after a remove.
removeHandler((item: T) => void) | nullConfirms and removes a record (null without remove).
checkRemoveHandler((item: T) => boolean) | undefinedremove.provider.check.
itemHandler((id: string) => void) | nullNavigates to / selects an id (null without item).
detailsComponentComponentType<any> | nulldetails.component, null without it (the details action then opens SmartDetailsPage).
detailsComponentPropsIDetailsOptions<T> | nullThe IDetailsOptions the details component gets as value, null without details.
detailsHandler((item: T) => void) | nullOpens the details of an item in a modal (null without details).
select((id: string) => void) | undefineddetails.provider.getData.
unselect(() => void) | undefineddetails.provider.clearData.
detailsButtonOptionsIButtonOptionsIButtonOptions that close the details (unselect).
loadNextPage(() => Promise<void>) | nullLoads the next page and scrolls to the top (null without pagination).
loadPrevPage(() => Promise<void>) | nullLoads the previous page and scrolls to the top.
pagenumber | nullpagination.page.
totalPagesnumber | nullpagination.totalPages.
handlePageChange(nextPage: number) => voidMoves to a page through the loaders (for SmartPaging's onPageChange).
infiniteScrollbooleantrue with PaginationMode.infiniteScroll and a next page.
infiniteScrollRefRefObject<HTMLDivElement | null>Attach to an element after the rows; the next page loads when it scrolls into view.
sortablebooleantrue with options.sort.
activeSortIListSortState | nullThe sort the headers show.
isSortable(key: string) => booleanWhether the header of a column sorts.
sortBy(key: string) => voidSorts by a column through provider.getData({ offset: 0, sortBy, sortDesc }).
getAriaSort(key: string) => 'ascending' | 'descending' | nullThe aria-sort of a header (only the active one has it).
getSortIndicator(key: string) => stringThe 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

  • SmartListDesktop is a table with a sticky header (LIST_DESKTOP_STICKY_HEADER_STYLE); the presets carry the Preline looks with smart:dark: variants, the desktop one driven by options.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.