Column mapping
Each column of a file, a sample of it, and the field it fills, or Skip.
import { ColumnMapping, guessMapping, mappingProblems } from "@forgeron/ui";| Column in the file | Field |
|---|---|
| NameFromagerie Roy · Garnier Transports | Field for Name |
| E-mailcontact@roy.fr · hugo@garnier.fr | Field for E-mail |
| Customer since2021-03-01 · 2024-09-12 | Field for Customer since |
| Internal codeR-104 · G-212 | Field for Internal code |
// The columns of a file and the field each one fills, guessed from their names. A required
// field left without a column is said under the table.
import { ColumnMapping, type DataField } from "@forgeron/ui";
const fields: DataField[] = [
{ id: "name", name: "name", type: "text", required: true },
{ id: "email", name: "email", type: "email" },
{ id: "city", name: "city", type: "text" },
{ id: "since", name: "customer_since", type: "date" },
];
export default function Default() {
return (
<div style={{ width: "min(520px, 100%)" }}>
<ColumnMapping
fields={fields}
columns={[
{ name: "Name", samples: ["Fromagerie Roy", "Garnier Transports"] },
{ name: "E-mail", samples: ["contact@roy.fr", "hugo@garnier.fr"] },
{ name: "Customer since", samples: ["2021-03-01", "2024-09-12"] },
{ name: "Internal code", samples: ["R-104", "G-212"] },
]}
/>
</div>
);
}API → Props
| Prop | Type | Default | Description |
|---|---|---|---|
columns | { name, samples? }[] | — | The columns of the file, a few values each. |
fields | DataField[] | — | { id, name, type, primary?, required?, unique?, readOnly?, defaultValue?, description?, choices?, relation?: { table, multiple? }, decimals? }. |
value / defaultValue | (fieldId | null)[] | — | Per column, the field it fills. Guessed from the names by default. |
onChange | (mapping) => void | — | When a column changes field. |
showProblems | boolean | true | Required fields left without a column, a field filled twice. |
className | string | — | Extra classes. |