Documentation
Tutorials
Workflows
Kebab actions
Daily Work
Dashboard & Reports
Quality Control
ISO 17025
Reagents & Storage
Logs
Contacts
Billing
Analysis Setup
Settings
Initial Setup
Help & Reference
Architecture decisions
Kebab actions
0:000:00

Export the samples grid to CSV

This recipe describes how to export the samples grid to a CSV file, so you can process it in a spreadsheet for batch analysis, customer reports, or accreditation submissions.


Goal

Produce a CSV file that contains the samples matching the free-text search term, in the grid's current sort order — ready for downstream processing outside the LIMS. The filter panel's criteria (status, customer, etc.) only narrow what's shown on screen; see the note below.


Prerequisites

  • You are signed in with read access to samples (any role that can open the /samples page).
  • You have an application that opens .csv files (Excel, LibreOffice Calc, Google Sheets, etc.).

Steps

  1. Navigate to the Samples page (/samples) from the side navigation.
  2. Optionally, open the filter panel via the filter icon in the title bar and apply the criteria you want to narrow the screenthese criteria do not carry over to the CSV file (see note below):
  • Date range (receivedDate — this filters the received date only, not the due date).
  • Sample status (e.g. Received, In Analysis, Analyzed, Subcontracted).
  • Customer (contact picker with type-ahead search).
  • Lab method, instrument.
  • SLA status (Approaching / Breached / On track) and the Show cancelled toggle.
  1. Use the search box or sort by a column to narrow or reorder the result set — these two are the only criteria that carry over verbatim into the CSV file.
  2. Click the CSV download icon in the title bar (before the orientation and print icons).
  3. The browser automatically downloads a file named samples-YYYYMMDD-HHmmss.csv. Open it in your spreadsheet of choice.
The exported columns are exactly those you have marked as visible via the column configuration — hidden columns and the actions column are skipped. If you need extra fields in the export, surface those columns first via the column-configuration dialog.

Important: only the free-text search term and the current sort order carry over into the CSV file. The filter panel's criteria (status, customer, lab method, instrument, date range, SLA, show cancelled) only narrow what's shown on screen — they are not applied to the CSV export. If you need a narrower subset in the file, use the search box.


What happens behind the scenes

The CSV button calls the fetchAndExportCsv helper (libs/utils/src/lib/csv-export.ts:102), which re-issues the findAllSamples GraphQL query with take = 0 and skip = 0 — that is, it asks for every row that matches the free-text search term and the current sort order, without paging. The wiring lives in apps/agrometrisis/src/app/samples/sample.ts:2634 (onExportCsv()), where only the current gridState() (filter, sortColumn, sortOrder) and the allColumns definition are passed in. The filter panel's criteria (status, customer, lab method, instrument, dates, SLA, show cancelled) live in a separate filterValues() signal and are not forwarded to this call — that's why they don't affect the CSV file, even though they filter the on-screen grid normally (via #buildFilterExtras(), which the paginated list and the PDF print both use, but the CSV export does not).

The result is serialised to CSV entirely in the browser: visible columns are selected, field values are escaped (" doubled), nested GraphQL relation objects (e.g. contact, labMethod) are resolved to human-readable strings, and ISO timestamps are truncated to YYYY-MM-DD. The file is prefixed with  (UTF-8 BOM) so Excel renders Greek characters correctly. No backend storage is involved — the file is built and downloaded purely through Blob + URL.createObjectURL.


Tips & notes

  • The query runs against every row that matches the search term — it is not restricted to the current page of the grid (nor to the other filters, see above). Don't hesitate to pull hundreds or thousands of rows in a single click.
  • For very large result sets (e.g. >20,000 rows) prefer a narrower search term for faster response — the filter panel's criteria won't help here, since they aren't applied to the CSV export.
  • If Greek characters look garbled when you open the CSV in Excel, make sure you open the file via File → Open (not double-click on older versions) so that the UTF-8 BOM is honoured.
  • Date columns are emitted in ISO format (YYYY-MM-DD). Excel will recognise them as real dates and let you sort or pivot directly.
  • The export captures the search term and sort order at the moment you click the icon. If you change either mid-export, simply re-click to regenerate the file.
  • Files are timestamped to the second, so consecutive exports never overwrite each other in your downloads folder.

The same CSV export pattern is wired into every grid page in the app — Contacts, Analyses, Invoices, Instruments, Control samples, Deviations, CAPA, Training records, and more. Each list page exposes the same CSV icon in its title bar, the same filter panel, and the same exportToCsv / fetchAndExportCsv plumbing.

See apps/agrometrisis/src/app/contacts/contact.ts:765 (onExportCsv()) as a parallel example for contacts — the only differences are the GraphQL query name (findAllContacts) and the extras block fed to the service. Once you learn the flow on one grid, you know them all.