CSV import

Since data is just an array, importing is not a table feature to configure — it's reading a file, parsing it, and calling setData. Upload a file below, or load the sample:

CSV import

Upload a .csv file, or load the sample data to see it parsed into the table.

Upload a CSV or load the sample to see it here

This demo uses Tailwind utility classes for layout — swap in your own CSS when copying into your project.

Read the file

Use FileReader to read the uploaded file as text:

function handleFile(file: File) {
  const reader = new FileReader();
  reader.onload = () => setData(parseCsv(String(reader.result)));
  reader.readAsText(file);
}

<input type="file" accept=".csv,text/csv" onChange={e => e.target.files?.[0] && handleFile(e.target.files[0])} />

Parse rows into your row type

A minimal parser is a few lines — split on newlines, split each line on commas, and zip against the header row. It doesn't handle quoted commas; reach for a library likepapaparse if your CSVs need that:

function parseCsv(text: string): Contact[] {
  const [headerLine, ...lines] = text.trim().split('\n');
  const headers = headerLine.split(',').map(h => h.trim());

  return lines.filter(Boolean).map(line => {
    const cells = line.split(',').map(c => c.trim());
    return Object.fromEntries(headers.map((h, i) => [h, cells[i] ?? ''])) as unknown as Contact;
  });
}

Pass it straight to data

No import prop, no adapter — the parsed array is the table's data:

const [data, setData] = useState<Contact[]>([]);

<DataTable columns={columns} data={data} />