mix live_table.gen.live (live_table v0.4.0)

View Source

Generates LiveView files with interactive data tables.

Creates the same files as phx.gen.live but replaces the basic table with an interactive LiveTable component featuring sorting, searching, and filtering.

Usage

$ mix live_table.gen.live Context Schema table_name field:type field:type

Example

$ mix live_table.gen.live Accounts User users name:string email:string age:integer active:boolean

What You Get

Your index page will automatically include:

  • Sortable columns - Click headers to sort by any field
  • Search functionality - Search across text fields
  • Smart filtering - Boolean toggles and numeric ranges
  • Responsive design - Works on mobile and desktop
  • Real-time updates - Live updates without page refresh

Field Behavior

Different field types get different capabilities:

  • String fields → Searchable and sortable
  • Text fields → Searchable (too long to sort effectively)
  • Boolean fields → Filterable with true/false toggle
  • Numeric fields → Filterable with min/max range sliders
  • ID fields → Sortable only

Arguments

Same as phx.gen.live:

  • Context: Business domain (e.g., Accounts, Blog)
  • Schema: Data model (e.g., User, Post)
  • table_name: Database table (e.g., users, posts)
  • fields: Field definitions (e.g., name:string email:string)

Next Steps

After running this command:

  1. Run mix ecto.migrate to create the database table
  2. Start your server and visit the generated routes
  3. Customize field configurations and filters as needed