csv
For codes made of digits — a postcode, a part number — that a spreadsheet would read as numbers.
| Type | 'text' |
|---|---|
| Default | not set |
Live update (update()) | Yes — give the columns again (update({ columns })) |
| Declared in | packages/core/src/columns/defs.ts |
What it does
Section titled “What it does”A spreadsheet opening a CSV file reads '01234' as the number 1234. With csv: 'text', a value made only of
digits is written ="01234", which Excel keeps as text, zeros included; in an Excel file (.xlsx) the cell is
written as text. Other values are written as usual.
Example
Section titled “Example”import { createGrid, type GridMessages } from '@dzgrid/dom';import { csvExport } from '@dzgrid/dom/export';import { EN_EXPORT } from '@dzgrid/dom/locales/en-export';import { EN } from '@dzgrid/dom/locales/en';
type Shop = { id: string; town: string; postcode: string };
const messages: GridMessages = { ...EN, text: { ...EN.text, ...EN_EXPORT.text } };
createGrid<Shop>(document.getElementById('shops')!, { rows: [{ id: 's1', town: 'Larkfield', postcode: '01234' }], columns: [ { id: 'town', header: 'Town' }, { id: 'postcode', header: 'Postcode', csv: 'text' }, ], getRowId: (r) => r.id, messages, features: [csvExport({ canExport: true })],});