
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
tanstack-table-export-to-csv
Advanced tools
The 'TANSTACK REACT TABLE EXPORT TO CSV' is a lightweight and user-friendly package for exporting tanstack react tables to CSV format
npm install tanstack-table-export-to-csv
or
yarn add tanstack-table-export-to-csv
or
pnpm add tanstack-table-export-to-csv
or
bun install tanstack-table-export-to-csv
getCsvBlobThe getCsvBlob function allows you to generate a Blob with CSV data, providing the flexibility to handle the export process on your own terms.
import {
createColumnHelper,
getFilteredRowModel,
useReactTable,
} from "@tanstack/react-table";
import { getCsvBlob } from "tanstack-table-export-to-csv";
type Person = {
firstName: string;
lastName: string;
age: number;
visits: number;
status: string;
progress: number;
};
const defaultData: Person[] = [
{
firstName: "tanner",
lastName: "linsley",
age: 24,
visits: 100,
status: "In Relationship",
progress: 50,
},
{
firstName: "tandy",
lastName: "miller",
age: 40,
visits: 40,
status: "Single",
progress: 80,
},
{
firstName: "joe",
lastName: "dirte",
age: 45,
visits: 20,
status: "Complicated",
progress: 10,
},
];
const columnHelper = createColumnHelper<Person>();
const columns = [
columnHelper.accessor("firstName", {
cell: (info) => info.getValue(),
footer: (info) => info.column.id,
}),
columnHelper.accessor((row) => row.lastName, {
id: "lastName",
cell: (info) => <i>{info.getValue()}</i>,
header: () => <span>Last Name</span>,
footer: (info) => info.column.id,
}),
columnHelper.accessor("age", {
header: () => "Age",
cell: (info) => info.renderValue(),
footer: (info) => info.column.id,
}),
columnHelper.accessor("visits", {
header: () => <span>Visits</span>,
footer: (info) => info.column.id,
}),
columnHelper.accessor("status", {
header: "Status",
footer: (info) => info.column.id,
}),
columnHelper.accessor("progress", {
header: "Profile Progress",
footer: (info) => info.column.id,
}),
];
function App() {
const [data, setData] = React.useState(() => [...defaultData]);
const table = useReactTable({
data,
columns,
getCoreRowModel: getCoreRowModel(),
});
const handleExportToCsv = (): void => {
const headers = table
.getHeaderGroups()
.map((x) => x.headers)
.flat();
const rows = table.getCoreRowModel().rows;
const csvBlob = getCsvBlob(headers, rows);
};
return (
<>
<button onClick={handleExportToCsv}>Export to csv</button>
</>
);
}
exportToCsvThe main powerhouse, exportToCsv, simplifies the process by creating a Blob and initiating the download.
import {
createColumnHelper,
getCoreRowModel,
useReactTable,
} from "@tanstack/react-table";
import { exportToCsv } from "tanstack-table-export-to-csv";
type Person = {
firstName: string;
lastName: string;
age: number;
visits: number;
status: string;
progress: number;
};
const defaultData: Person[] = [
{
firstName: "tanner",
lastName: "linsley",
age: 24,
visits: 100,
status: "In Relationship",
progress: 50,
},
{
firstName: "tandy",
lastName: "miller",
age: 40,
visits: 40,
status: "Single",
progress: 80,
},
{
firstName: "joe",
lastName: "dirte",
age: 45,
visits: 20,
status: "Complicated",
progress: 10,
},
];
const columnHelper = createColumnHelper<Person>();
const columns = [
columnHelper.accessor("firstName", {
cell: (info) => info.getValue(),
footer: (info) => info.column.id,
}),
columnHelper.accessor((row) => row.lastName, {
id: "lastName",
cell: (info) => <i>{info.getValue()}</i>,
header: () => <span>Last Name</span>,
footer: (info) => info.column.id,
}),
columnHelper.accessor("age", {
header: () => "Age",
cell: (info) => info.renderValue(),
footer: (info) => info.column.id,
}),
columnHelper.accessor("visits", {
header: () => <span>Visits</span>,
footer: (info) => info.column.id,
}),
columnHelper.accessor("status", {
header: "Status",
footer: (info) => info.column.id,
}),
columnHelper.accessor("progress", {
header: "Profile Progress",
footer: (info) => info.column.id,
}),
];
function App() {
const [data, setData] = React.useState(() => [...defaultData]);
const table = useReactTable({
data,
columns,
getCoreRowModel: getCoreRowModel(),
});
const handleExportToCsv = (): void => {
const headers = table
.getHeaderGroups()
.map((x) => x.headers)
.flat();
const rows = table.getCoreRowModel().rows;
exportToCsv("persons_data", headers, rows);
};
return (
<>
<button onClick={handleExportToCsv}>Export to csv</button>
</>
);
}
getHeaderNamesA handy utility function, getHeaderNames, helps in obtaining text versions of headers.
import {
createColumnHelper,
getFilteredRowModel,
useReactTable,
} from "@tanstack/react-table";
import { getHeaderNames } from "tanstack-table-export-to-csv";
const columnHelper = createColumnHelper<Person>();
const columns = [
columnHelper.accessor("firstName", {
cell: (info) => info.getValue(),
footer: (info) => info.column.id,
}),
columnHelper.accessor((row) => row.lastName, {
id: "lastName",
cell: (info) => <i>{info.getValue()}</i>,
header: () => <span>Last Name</span>,
footer: (info) => info.column.id,
}),
columnHelper.accessor("age", {
header: () => "Age",
cell: (info) => info.renderValue(),
footer: (info) => info.column.id,
}),
columnHelper.accessor("visits", {
header: () => <span>Visits</span>,
footer: (info) => info.column.id,
}),
columnHelper.accessor("status", {
header: "Status",
footer: (info) => info.column.id,
}),
columnHelper.accessor("progress", {
header: "Profile Progress",
footer: (info) => info.column.id,
}),
];
const table = useReactTable({
data,
columns,
getFilteredRowModel: getFilteredRowModel(),
});
const headers = table
.getHeaderGroups()
.map((x) => x.headers)
.flat();
const headerNames = getHeaderNames(headers);
// Result: ['firstName', 'Last Name', 'Age', 'Visits', 'Status', 'Profile Progress']
Feel free to contribute and make the TANSTACK REACT TABLE EXPORT TO CSV even more awesome! 🚀✨
This module is licensed under the MIT License - see the LICENSE file for details.
FAQs
The 'TANSTACK REACT TABLE EXPORT TO CSV' is a lightweight and user-friendly package for exporting tanstack react tables to CSV format
The npm package tanstack-table-export-to-csv receives a total of 3,710 weekly downloads. As such, tanstack-table-export-to-csv popularity was classified as popular.
We found that tanstack-table-export-to-csv demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.