Installation
React Router
Use this path for React Router framework apps.
Create or open a React Router app
If you need a new app, create one first:
pnpm create react-router@latest my-appcd my-appnpm create react-router@latest my-appcd my-appyarn create react-router my-appcd my-appbun create react-router@latest my-appcd my-appThe standard template includes Tailwind CSS and the ~/* import alias.
Install react-datatable
React Router apps usually keep app code under app/, so target that directory:
pnpm dlx @react-datatable/cli install --token <license-token> --framework react-router --target app/react-datatablenpx @react-datatable/cli install --token <license-token> --framework react-router --target app/react-datatableyarn dlx @react-datatable/cli install --token <license-token> --framework react-router --target app/react-datatablebunx @react-datatable/cli install --token <license-token> --framework react-router --target app/react-datatableCreate a table component
Create app/components/CustomersTable.tsx:
import { Datatable, type DatatableColumn } from "~/react-datatable"
type Customer = { id: string; company: string }
const rows: Customer[] = [
{ id: "1", company: "Acme Inc." },
{ id: "2", company: "Globex" },
{ id: "3", company: "Initech" },
{ id: "4", company: "Umbrella" },
{ id: "5", company: "Stark Industries" },
]
const columns: DatatableColumn<Customer>[] = [
{ id: "company", accessorKey: "company", header: "Company", filterType: "text" },
]
export function CustomersTable() {
return <Datatable tableKey="customers" columns={columns} data={rows} getRowId={(row) => row.id} />
}Render it in a route
Import the component into app/routes/home.tsx or your chosen route file:
import { CustomersTable } from "~/components/CustomersTable"
export default function Home() {
return (
<main className="p-6">
<CustomersTable />
</main>
)
}