Command Palette

Search for a command to run...

Docs
Reorderable Table

Reorderable Table

A customizable table component with drag-and-drop column reordering, column visibility controls, and persistent layout settings.

Loading...

Installation

Usage

import ReorderableTable from "@/components/ui/reorderable-table";
 
const data = [
  {
    id: 1,
    name: "John Doe",
    email: "[email protected]",
    role: "Developer",
    location: "New York",
    status: "Active",
    balance: 1250,
  },
  // ... more data
];
 
const columns = [
  { key: "name", label: "Name", width: "220px" },
  { key: "email", label: "Email", width: "260px" },
  { key: "role", label: "Role", width: "140px" },
  // ... more columns
];
 
export default function MyTable() {
  return (
    <ReorderableTable
      data={data}
      columns={columns}
      title="My Reorderable Table"
      searchable={true}
    />
  );
}

Props

PropTypeDefaultDescription
dataT[]defaultRowsArray of data objects to display in the table
columnsColumnDef<T>[]defaultColumnsColumn definitions with keys, labels, and optional rendering
lsOrderKeystring"reorderable_table_order_v1"LocalStorage key for persisting column order
lsVisibleKeystring"reorderable_table_visible_v1"LocalStorage key for persisting column visibility
searchablebooleantrueWhether to show the search input
titlestring"Reorderable Table"Table title displayed at the top

Column Definition

PropertyTypeDescription
keykeyof TThe data property key this column represents
labelstringDisplay label for the column header
widthstringOptional CSS width value for the column
stickybooleanWhether the column should be sticky (not implemented)
render(row: T) => React.ReactNodeOptional custom render function for cell content

Features

  • Drag & Drop Reordering: Drag column headers to reorder columns
  • Column Visibility: Toggle column visibility with checkboxes
  • Persistent Layout: Column order and visibility saved to localStorage
  • Search Functionality: Built-in search across all visible columns
  • Custom Rendering: Support for custom cell renderers
  • Responsive Design: Horizontal scrolling on smaller screens