Export, multiselect and groups
Three features turn the list from a table into a working screen: downloading it, editing many records at once, and breaking it into groups. All three are switched on from the configuration.
Export
export: true adds the export button to the list page header. It opens a popover with two buttons, CSV and XLSX, and the popover closes itself once the store reports the export as finished.
export: true adds the export button to the list page header. It opens SmartCrudExport in a modal of ModalService, which the SmartOverlays of SmartProvider render: two buttons, CSV and XLSX, and the modal closes itself once the store reports the export as finished: the component calls the dismiss prop ModalService hands it, and without one closes the last opened modal.
What is exported is what is on screen, minus the paging. The component takes the current filter, clears its limit and offset, and asks for every matching record rather than the current page. The service then issues the ordinary reading request with the format's content type as the request's content type, which is what tells the backend to answer with a file. The response is turned into a blob and handed to the browser as a download named data.csv or data.xlsx. The CSV blob is prefixed with a byte order mark so that spreadsheet applications open it as UTF-8.
On the server the same reading route serves all three formats, and the content type of the request picks between them.
| Request content type | Response |
|---|---|
text/csv | The matching records serialised to CSV. |
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet | The same records as an XLSX workbook. |
| Anything else | JSON with the data, the total count and the links. |
Before serialising, the controller flattens each record: nested objects become underscore-joined columns, arrays are skipped entirely, HTML tags are stripped out of strings, and dates are rendered in the Europe/Warsaw time zone. Columns are the union of the keys it found, and a key that never produced a value is dropped from the rows. An export also asks the database to allow disk use, because it is deliberately unpaged.
An export is bounded by its own limit, maxExportLimit in the options of CrudShellNestjsModule.forRoot(), 10000 rows by default, instead of the list's maxQueryLimit. It is never cut short silently. An export without limit, which is what the button sends, that matches more rows than maxExportLimit is answered with 400 Bad Request and a message naming the limit; narrow the filters, raise the limit, or fetch the file in pages with limit and offset. Every export carries the number of matching rows in the X-Total-Count header.
The CSV is safe to open in a spreadsheet. A text cell that starts with =, +, - or @, also after leading spaces, or that starts with a tab or a line break, is prefixed with an apostrophe so that the spreadsheet shows it as text instead of running it as a formula. This follows the OWASP guidance on CSV injection, and it is visible: a phone number such as +48 600 000 000 is exported as '+48 600 000 000. Numbers stay numbers, so a negative amount is not affected. Import text columns as text when the file feeds another system.
Multiselect
Multiselect turns the list into a bulk editor for the fields that allow it.
The button appears when list.components.multi is set, or when edit is on and at least one field declares update: { multi: true }, the device is not mobile and the list is in desktop mode. Pressing it clears any existing selection and switches the list into multi-selection.
The button appears when list.components.multi is set, or when edit is on and at least one field declares update: { multi: true } and the list is in desktop mode or has no mode. The device is not detected. Pressing it clears any existing selection and switches the list into multi-selection, a checkbox per row.
From then on, every change to the selection opens the multiselect panel in the end menu, or closes it again when the selection empties, and pushes the selected records into the store. The panel reads them back through the facade's multiSelected state and builds a form of exactly the fields marked multi. Where every selected record already shares the same value for such a field, the form is prefilled with it; where they differ, it is left empty. Confirming applies the edited values to every selected record through one partial update per record, and closes the panel.
Navigating away clears the selection: the page watches the router, in React the navigation adapter, and drops both the selection and the multi-selection mode on every navigation event.
The end menu belongs to the application
The list page opens the multiselect panel, and the filters panel, through MenuService.openEnd, with the component bound to the feature by useCrudBoundComponent, so it works outside the feature's CrudProvider. MenuService only keeps the request in its endContent store, and SmartApp renders no menu, so the application renders it. Without that, the multiselect and filters buttons appear to do nothing.
import {
CrudFullConfig,
CrudProvider,
SmartCrudListPage,
} from '@smartsoft001/crud-shell-react';
import { IEntity } from '@smartsoft001/domain-core';
import { Field, FieldType, Model } from '@smartsoft001/models';
import { useMenuService, useStore } from '@smartsoft001/react';
@Model({ titleKey: 'title' })
export class Task implements IEntity<string> {
id!: string;
@Field({ type: FieldType.text, list: true, details: true, update: true })
title!: string;
// `multi` makes the field editable for a whole selection at once.
@Field({ type: FieldType.text, list: true, update: { multi: true } })
owner!: string;
}
export const tasksConfig: CrudFullConfig<Task> = {
apiUrl: 'https://api.example.com/tasks',
entity: 'tasks',
type: Task,
title: 'Tasks',
edit: true,
export: true,
pagination: { limit: 25 },
};
// The end menu belongs to the application. The list page opens the
// multiselect panel (and the filters) in it through MenuService, bound to
// the feature, so the menu can live outside the CrudProvider.
function EndMenu() {
const menuService = useMenuService();
const content = useStore(menuService.endContent);
if (!content) return null;
const { component: Component, props } = content;
return (
<aside aria-label="End menu">
<Component {...props} />
</aside>
);
}
export function TasksScreen() {
return (
<>
<CrudProvider config={tasksConfig}>
<SmartCrudListPage basePath="/tasks" />
</CrudProvider>
<EndMenu />
</>
);
}
The spec drives both features through this screen. Export: the button opens CSV and XLSX in a modal, CSV sends GET https://api.example.com/tasks with Content-Type: text/csv and no paging, the browser is handed data.csv, and after an XLSX export the modal is gone. Multiselect: the button adds a checkbox per row, checking one opens the end menu titled selected: 1, two records that share an owner prefill it and two that do not leave it empty, and confirming a new owner sends PATCH https://api.example.com/tasks/1 and /tasks/2, each with { owner, id }, and closes the menu.
Groups
list.groups breaks the collection into disclosure sections instead of one flat list. Each entry names the field to filter on, the value that defines the group, the label to show, whether it starts open, and optionally nested children, which render as a group inside a group.
| Field | Type | Effect |
|---|---|---|
key | string | The field the group filters on. |
value | string | The value that defines membership of the group. |
text | string | The label, translated before it is rendered. |
show | boolean | Whether the group starts expanded. |
children | Array<ICrudListGroup> | A nested level of groups, rendered indented inside the parent. |
Opening a group is a query change, not a client-side filter. The group service, CrudListGroupService, adds a hidden equality entry for the group's key and value to the current filter and re-reads from the first page, which is why only one group is open at a time: opening one closes the others, and a group on the same key replaces the value of the entry. Closing a group leaves its entry in the filter; the entries go when the groups do. Leaving the page, starting a search, or closing a parent group, whose child groups then go away, removes the entries those groups added, in one debounced read rather than one per group. The entries are marked hidden, so they never show up among the active-filter chips.
While groups are configured, the plain list is hidden and the grouped view takes its place. Searching reverses that: as soon as the filter carries search text, the flat list comes back, because a search is a question about the whole collection rather than about one group.
Examples
None of these three features has an executable example in these docs. They are described here from the component sources. The configuration fields that switch them on, export, list.components.multi and list.groups, are part of the type that the configuration example compiles against, so their names and shapes cannot drift, but no test in this repository mounts the export popover, the multiselect panel or the grouped list.
Export and multiselect are executed by the example under multiselect, against the real store and effects over a stubbed fetch. Groups are described here from the component source: SmartCrudGroup renders them, and the standard list body puts it in place of the flat list while list.groups is set and nothing is searched. No spec in these docs mounts the grouped list.
Where next
- List page is where all three features are switched on and rendered.
- Filters and search explains the query that the export reuses and the groups extend.
- Configuration lists the fields behind each feature.
- Overview has the backend module that serves the exported file.