Installation
Vite
Use this path for a Vite app with React, TypeScript, and Tailwind CSS.
Create or open a Vite React app
If you need a new app, create one with the React + TypeScript template:
pnpm create vite my-app --template react-tscd my-apppnpm installnpm create vite@latest my-app -- --template react-tscd my-appnpm installyarn create vite my-app --template react-tscd my-appyarn installbun create vite my-app --template react-tscd my-appbun installConfigure Tailwind CSS
Install Tailwind for Vite when your app does not have it yet:
pnpm add -D tailwindcss @tailwindcss/vitenpm install -D tailwindcss @tailwindcss/viteyarn add -D tailwindcss @tailwindcss/vitebun add --dev tailwindcss @tailwindcss/viteAdd the Tailwind Vite plugin to vite.config.ts:
import tailwindcss from "@tailwindcss/vite"
import react from "@vitejs/plugin-react"
import { defineConfig } from "vite"
export default defineConfig({
plugins: [react(), tailwindcss()],
})Make sure src/index.css imports Tailwind:
@import "tailwindcss";Install react-datatable
Run the installer from the app root:
pnpm dlx @react-datatable/cli install --token <license-token> --framework vitenpx @react-datatable/cli install --token <license-token> --framework viteyarn dlx @react-datatable/cli install --token <license-token> --framework vitebunx @react-datatable/cli install --token <license-token> --framework viteThe default target is src/react-datatable.
Create a table component
Create src/components/CustomersTable.tsx and import from the copied source:
import { Datatable, type DatatableColumn } from "../react-datatable"
type Customer = { id: string; company: string; status: string }
const rows: Customer[] = [
{ id: "1", company: "Acme Inc.", status: "Active" },
{ id: "2", company: "Globex", status: "Trial" },
{ id: "3", company: "Initech", status: "Active" },
{ id: "4", company: "Umbrella", status: "Paused" },
{ id: "5", company: "Stark Industries", status: "Active" },
]
const columns: DatatableColumn<Customer>[] = [
{ id: "company", accessorKey: "company", header: "Company", filterType: "text" },
{ id: "status", accessorKey: "status", header: "Status", filterType: "text-list" },
]
export function CustomersTable() {
return <Datatable tableKey="customers" columns={columns} data={rows} getRowId={(row) => row.id} />
}Render the table in src/App.tsx
Replace the default app content with your table component:
import { CustomersTable } from "./components/CustomersTable"
export default function App() {
return (
<main className="p-6">
<CustomersTable />
</main>
)
}