This is a Shadcn table component with server-side sorting, filtering, and pagination. It is bootstrapped with create-t3-app
.
Warning This project is still in development and is not ready for production use.
It uses new technologies ( ppr, drizzle ORM) which are subject to change and may break your application.
- Framework: Next.js
- Styling: Tailwind CSS
- UI Components: shadcn/ui
- Table package: TanStack/react-table
- Database: PlanetScale
- ORM: Drizzle ORM
- Validation: Zod
- Optimizing compiler: million
- Server-side pagination, sorting, and filtering (
useTable
hook) - Customizable columns (
dataTable
andcolumns
props) - Dynamic debounced search inputs (
searchableColumns
prop) - Dynamic faceted filters (
filterableColumns
prop) - Optional notion like advanced filtering (
advancedFilter
prop) - Optional floating bar on row selection, rendred at the bottom (
floatingBarContent
prop) - Action to delete rows (
deleteRowsAction
prop)
-
Clone the repository
git clone https://github.com/sadmann7/shadcn-table
-
Install dependencies using pnpm
pnpm install
-
Copy the
.env.example
to.env
and update the variables.cp .env.example .env
-
Start the development server
pnpm run dev
-
Push the database schema
pnpm run db:push
Watch the codebase overview video on YouTube.
Consider subscribing to Kavin's YouTube channel for more videos.
Follow the deployment guides for Vercel, Netlify and Docker for more information.
-
Clone the Repo
git clone https://github.com/sadmann7/shadcn-table
OR
git clone https://github.com/arvind-iyer-2001/shadcn-table
-
Copy the following folders and files into your project (configured with ) at the exact specific locations
src/components/data-table
src/db/index.ts
src/hooks
src/lib
src/types
Also install the required shadcn components and other required packages with the following commands:
pnpm dlx shadcn-ui@latest init pnpm dlx shadcn-ui@latest add button badge checkbox command dialog dropdown-menu input popover select separator skeleton table toast pnpm add drizzle-orm @planetscale/database @tanstack/react-table zod drizzle-zod sonner @t3-oss/env-nextjs pnpm add -D drizzle-kit dotenv-cli tsx
-
Configure your Environment Variables Then set up the Database URL, for this example, we're using PlanetScale MySQL2 Database. Our schemas will also be made using this.
-
Database Actions: For this you can use any ORM of your choice, but for the sake of this particular example, we're using Drizzle ORM and PlanetScale.
As an example, lets use the
tasks
table.- Create the Table Schema at
@/db/schema.ts
- Create the associated zod validations
@/lib/validations/tasks.ts
file
- Create the Table Schema at
-
Setting up the Table
- Start with creating a
page.tsx
file, and if necessary, alayout.tsx
file in the app directory - Copy the contents of the
./_components
and./_lib
directories into your project wherever needed. - Modify each of the files according to your database table.
- Modify the required actions for querying and mutating data in the folder
./_lib/queries
in thequeries.ts
andactions.ts
. - Modify the
./_components/task-table-column-def.tsx
file to define the column header, searchable columns, filterable columns, and the column based actions and the presentation of the data in each column. - Modify the
./_components/tasks-table-actions.tsx
file to define the the selected rows based actions, like deleting and modifying a group of rows, and floating bar content (can be used in thefloatingBarContent
prop of theDataTable
component asTasksTableFloatingBarContent(dataTable)
) - Modify the
./_components/task-table.tsx
file to reference the schemas, types and database actions to be used in the table. ThegetTasksPromise
is fetched here using theReact.use
hook. Components and Data that have to be memoized must be declared here, because it can not be done in a server component. - Modify the
./page.tsx
file to define thegetTasksPromise
to be used in theTasksTableShell
component.
- Start with creating a