Giter Club home page Giter Club logo

shadcn-table's Introduction

This is a Shadcn table component with server-side sorting, filtering, and pagination. It is bootstrapped with create-t3-app.

Shadcn Table

Warning This project is still in development and is not ready for production use.

It uses new technologies (ppr, and drizzle ORM) which are subject to change and may break your application.

Tech Stack

Features

  • Server-side pagination, sorting, and filtering (via useDataTable hook)
  • Customizable columns (dataTable and columns 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 (floatingBar prop)
  • Action to delete rows (deleteRowsAction prop)

Running Locally

  1. Clone the repository

    git clone https://github.com/sadmann7/shadcn-table
  2. Install dependencies using pnpm

    pnpm install
  3. Copy the .env.example to .env and update the variables.

    cp .env.example .env
  4. Start the development server

    pnpm run dev
  5. Push the database schema

    pnpm run db:push

Codebase Overview

Watch the codebase overview video on YouTube.

Consider subscribing to Kavin Desi Valli's YouTube channel for more videos.

How do I deploy this?

Follow the deployment guides for Vercel, Netlify and Docker for more information.

How to use the data-table component

  1. Clone the Repo

    git clone https://github.com/sadmann7/shadcn-table

    OR

    git clone https://github.com/arvind-iyer-2001/shadcn-table
  2. 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 postgres @tanstack/react-table zod sonner @t3-oss/env-nextjs
    pnpm add -D drizzle-kit dotenv-cli pg tsx
  3. 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.

  4. 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 Neon.

    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
  5. Setting up the Table

    • Create Files: Create page.tsx and, if needed, layout.tsx in your app directory.
    • Copy Directories: Copy ./_components and ./_lib directories into your project.
    • Update Queries/Mutations: Modify ./_lib/queries.ts, ./_lib/actions.ts, and ./_lib/mutations.ts to match your database operations.
    • Update Floating Bar: Update ./_components/tasks-table-floating-bar.tsx to match your table's actions (optional).
    • Define Table Columns: Update ./_components/tasks-table-columns.tsx to define column headers, actions, searchable and filterable columns.
    • Setup Data Fetching: In ./page.tsx, define getTasksPromise for use in ./_components/tasks-table.tsx.
    • Fetch Data: In ./_components/tasks-table.tsx, consume the getTasksPromise promise using the React.use hook. The promise is passed to trigger the suspense boundary.
    • Memoize Table Columns: In ./_components/tasks-table.tsx, memoize columns defined in ./_components/tasks-table-columns.tsx using React.useMemo hook to prevent unnecessary re-renders.
    • Use Data Table Hook: In ./_components/tasks-table.tsx, call ./hooks/useTasksTable.tsx hook to handle server-side pagination, sorting, and filtering.
    • Remove Demo Inputs: Make sure to remove demo inputs from ./components/task-table.tsx. These were used to show the advanced filter and floating bar features.

shadcn-table's People

Contributors

renovate[bot] avatar sadmann7 avatar kavinvalli avatar mohitkumawat310 avatar yuvarajmadineni avatar aqib-rime avatar cesarscfilho avatar dewodt avatar fellipeutaka avatar noxify avatar

Stargazers

Emerson Dantas  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.