tablecn

repository·main·Indexed 27 days ago

https://github.com/sadmann7/tablecn

Advanced data table and data grid components built with shadcn/ui. Version 0.1.0 supports server-side pagination, filtering, infinite scrolling, and real-time multiplayer collaboration. It includes a robust filtering system compatible with @tanstack/react-table, Drizzle ORM integration for PostgreSQL, and utilities for column pinning, TSV parsing, and cell variant management.

Tokens
4.8K
Snippets
20
Records
45
Agent score
92%

What's inside tablecn

  1. Manual Setup

    main

    If you prefer to manage the database and dev server manually, follow these steps:

    1. Clone the repository and enter the directory.
    2. Install dependencies using pnpm.
    3. Copy .env.example to .env and update it with your specific database credentials.
    4. Start the PostgreSQL container using pnpm db:start.
    5. Push the schema and seed data using pnpm db:setup.
    6. Start the Next.js development server using pnpm dev.
    git clone https://github.com/sadmann7/tablecn
    cd tablecn
    pnpm install
    cp .env.example .env
    pnpm db:start
    pnpm db:setup
    pnpm dev
  2. Quick Setup with Docker

    main

    To quickly get the project running with a pre-configured PostgreSQL instance via Docker, follow these steps:

    1. Clone the repository and enter the directory.
    2. Copy the environment variables from the example file.
    3. Run the ollie command to automate dependency installation, starting the Docker PostgreSQL instance, pushing the schema, and seeding sample data.
    git clone https://github.com/sadmann7/tablecn
    cd tablecn
    cp .env.example .env
    pnpm ollie
  3. Deploy the Multiplayer demo

    main

    The multiplayer features require a separate deployment using PartyKit. Use the deploy:multiplayer command to deploy.

    Important: After deploying, you must set the NEXT_PUBLIC_PARTYKIT_HOST environment variable in your deployment environment to point to your PartyKit host.

    pnpm deploy:multiplayer
  4. Run the Multiplayer demo locally

    main

    To run the real-time collaboration (multiplayer) demo on your local machine, use the dev:multiplayer command. This starts both the Next.js and PartyKit development servers concurrently.

    pnpm dev:multiplayer
  5. Configure Drizzle ORM for tablecn

    main

    The drizzle.config.ts file defines the configuration for Drizzle Kit used to manage database migrations and schema synchronization. It uses the postgresql dialect and targets a specific schema file and output directory. To ensure migrations only affect relevant tables, it uses a tablesFilter based on a DATABASE_PREFIX.

    import type { Config } from "drizzle-kit";
    import { env } from "@/env.js";
    import { DATABASE_PREFIX } from "@/lib/constants";
    
    export default {
      schema: "./src/db/schema.ts",
      dialect: "postgresql",
      out: "./drizzle",
      dbCredentials: {
        url: env.DATABASE_URL,
      },
      tablesFilter: [`${DATABASE_PREFIX}_*`],
    } satisfies Config;
  6. Configure the PostgreSQL service via Docker Compose

    main

    The postgres service in the docker-compose.yml file uses environment variables for configuration. You must provide these variables in your environment or a .env file to ensure the database initializes correctly and is accessible.

    Required environment variables:

    • DATABASE_PORT: The host port to map to the container's port 5432.
    • DATABASE_PASSWORD: The password for the POSTGRES_USER.
    • DATABASE_USER: The username for the database.
    • DATABASE_NAME: The name of the initial database to create.
    services:
      postgres:
        image: postgres:17.4
        restart: always
        ports:
          - ${DATABASE_PORT}:5432
        environment:
          - POSTGRES_PASSWORD=${DATABASE_PASSWORD}
          - POSTGRES_USER=${DATABASE_USER}
          - POSTGRES_DB=${DATABASE_NAME}
        volumes:
          - ./docker-data/db:/var/lib/postgresql/data
        healthcheck:
          test: ["CMD-SHELL", "pg_isready -U ${DATABASE_USER} -d ${DATABASE_NAME}"]
          interval: 10s
          timeout: 5s
          retries: 5
  7. Use the built-in TanStack Table filter function

    main

    The getFilterFn<TData>() function returns a FilterFn compatible with @tanstack/react-table. It handles complex filter objects containing an operator, a value, and an optional endValue (used for range filters like isBetween).

    Supported operators vary by type, but common ones include:

    • Text: contains, notContains, equals, notEquals, startsWith, endsWith, isEmpty, isNotEmpty
    • Number: equals, notEquals, lessThan, lessThanOrEqual, greaterThan, greaterThanOrEqual, isBetween, isEmpty, isNotEmpty
    • Date: equals, notEquals, before, after, onOrBefore, onOrAfter, isBetween, isEmpty, isNotEmpty
    • Select: is, isNot, isAnyOf, isNoneOf, isEmpty, isNotEmpty
    • Boolean: isTrue, isFalse
  8. Configure cell variants via ColumnMeta

    main
    When defining columns for @tanstack/react-table, you can extend ColumnMeta to specify how a cell should behave and render using the cell property. This allows you to define input types like selects, checkboxes, or file uploads directly in your column definitions.