### Real-World Example: Custom Header with Card Mode Source: https://github.com/gurujada/live_table/blob/master/docs/configuration.md An example demonstrating a custom header and card mode configuration for a college counselling interface. ```elixir # table_options with custom header def table_options do %{ mode: :card, card_component: &CounsellingWeb.CollegeComponent.college_component/1, custom_header: {CounsellingWeb.CollegeLive.CustomHeader, :custom_header} } end ``` -------------------------------- ### Install Typst on Ubuntu/Debian Source: https://github.com/gurujada/live_table/blob/master/docs/api/exports.md Steps to download, extract, and install the Typst binary on Ubuntu or Debian systems. ```bash # Download latest release wget https://github.com/typst/typst/releases/latest/download/typst-x86_64-unknown-linux-musl.tar.xz tar -xf typst-x86_64-unknown-linux-musl.tar.xz sudo mv typst-x86_64-unknown-linux-musl/typst /usr/local/bin/ ``` -------------------------------- ### Install LiveTable Source: https://github.com/gurujada/live_table/blob/master/README.md Run this command in your terminal to install the LiveTable dependency and assets. ```bash mix deps.get && mix live_table.install ``` -------------------------------- ### Install Typst for PDF Exports (Ubuntu/Debian) Source: https://github.com/gurujada/live_table/blob/master/docs/installation.md Install Typst on Ubuntu/Debian systems by downloading the binary and placing it in your PATH. ```bash wget https://github.com/typst/typst/releases/latest/download/typst-x86_64-unknown-linux-musl.tar.xz tar -xf typst-x86_64-unknown-linux-musl.tar.xz sudo mv typst-x86_64-unknown-linux-musl/typst /usr/local/bin/ ``` -------------------------------- ### Install Typst for PDF Exports Source: https://github.com/gurujada/live_table/blob/master/docs/troubleshooting.md Install the Typst typesetting system to enable PDF export functionality. Follow the instructions for your operating system and verify the installation. ```bash # macOS brew install typst ``` ```bash # Ubuntu/Debian wget https://github.com/typst/typst/releases/latest/download/typst-x86_64-unknown-linux-musl.tar.xz tar -xf typst-x86_64-unknown-linux-musl.tar.xz sudo mv typst-x86_64-unknown-linux-musl/typst /usr/local/bin/ ``` ```bash # Verify installation typst --version ``` -------------------------------- ### Application-Wide Configuration Example Source: https://github.com/gurujada/live_table/blob/master/docs/api/table-options.md Shows how to set default options for all LiveTables within an application by configuring the `:live_table` application. ```APIDOC ## Application-Wide Configuration Set defaults for all tables in your application: ```elixir # config/config.exs config :live_table, defaults: %{ pagination: %{ enabled: true, sizes: [20, 50, 100] }, sorting: %{ default_sort: [inserted_at: :desc] }, exports: %{ enabled: true, formats: [:csv, :pdf] } } ``` ``` -------------------------------- ### Verify Typst Installation Source: https://github.com/gurujada/live_table/blob/master/docs/installation.md Check if Typst is installed correctly by running the version command. ```bash typst --version ``` -------------------------------- ### Install LiveTable Generator Source: https://github.com/gurujada/live_table/blob/master/usage_rules.md Commands to install the LiveTable generator. Use the `--oban` flag if you intend to use Oban for export functionality. ```bash mix live_table.install ``` ```bash mix live_table.install --oban # With Oban for exports ``` -------------------------------- ### Run Oban Migrations Source: https://github.com/gurujada/live_table/blob/master/docs/installation.md After configuring Oban, run its installation task and Ecto migrations to set up the necessary database tables. ```bash mix oban.install mix ecto.migrate ``` -------------------------------- ### Simple Table Setup with LiveResource Source: https://github.com/gurujada/live_table/blob/master/docs/README.md Use this pattern to set up a simple table by directly referencing your Ecto schema. ```elixir use LiveTable.LiveResource, schema: YourApp.Product ``` -------------------------------- ### Run LiveTable Installer Source: https://github.com/gurujada/live_table/blob/master/docs/generators/live_table.install.md Execute the `mix live_table.install` command to automatically configure your Phoenix application for LiveTable. ```bash mix live_table.install ``` -------------------------------- ### Run LiveTable Installer with Oban Source: https://github.com/gurujada/live_table/blob/master/docs/generators/live_table.install.md Use the `--oban` flag with `mix live_table.install` to configure Oban for CSV/PDF exports. ```bash mix live_table.install --oban ``` -------------------------------- ### Custom Query Data Provider Setup Source: https://github.com/gurujada/live_table/blob/master/usage_rules.md When using custom queries, ensure a `data_provider` is assigned in the `mount/3` function. This example shows the missing assignment, which leads to errors. ```elixir # Wrong - Custom query without data provider use LiveTable.LiveResource def fields do [complex_field: %{label: "Complex"}] end # Missing: data_provider assignment in mount/3 ``` -------------------------------- ### E-commerce Product Filters Example Source: https://github.com/gurujada/live_table/blob/master/docs/api/filters.md An example demonstrating how to set up filters for an e-commerce product listing, including active products, price range, category search, low stock alerts, and new arrivals. ```elixir def filters do [ # Active products toggle active: Boolean.new(:active, "active", %{ label: "Show Active Products Only", condition: dynamic([p], p.active == true) }), # Price range slider price_range: Range.new(:price, "price_range", %{ type: :number, label: "Price Range", unit: "$", min: 0, max: 2000, step: 25, default_min: 0, default_max: 500 }), # Category dropdown with search category: Select.new({:categories, :name}, "category", %{ label: "Category", placeholder: "Search categories...", options_source: {Shop.Catalog, :search_categories, []} }), # Stock level toggle low_stock: Boolean.new(:stock_quantity, "low_stock", %{ label: "Low Stock Alert (< 10 items)", condition: dynamic([p], p.stock_quantity < 10 and p.stock_quantity > 0) }), # Recently added toggle new_arrivals: Boolean.new(:inserted_at, "new_arrivals", %{ label: "New Arrivals (Last 30 Days)", condition: dynamic([p], p.inserted_at >= ago(30, "day") ) }) ] end ``` -------------------------------- ### Start Oban in Application Supervision Tree Source: https://github.com/gurujada/live_table/blob/master/docs/generators/live_table.install.md If Oban is configured for exports, add it to your application's supervision tree in `lib/your_app/application.ex` to ensure it starts correctly. ```elixir children = [ # ... other children {Oban, Application.fetch_env!(:your_app, Oban)} ] ``` -------------------------------- ### Install Typst for PDF Exports (macOS) Source: https://github.com/gurujada/live_table/blob/master/docs/installation.md Install Typst using Homebrew on macOS. This is a prerequisite for PDF export functionality. ```bash brew install typst ``` -------------------------------- ### Basic Table Setup with LiveResource Source: https://context7.com/gurujada/live_table/llms.txt Set up a data table using LiveTable.LiveResource with an Ecto schema. Define fields, filters, and custom renderers for columns. ```elixir defmodule YourAppWeb.ProductLive.Index do use YourAppWeb, :live_view use LiveTable.LiveResource, schema: YourApp.Catalog.Product def fields do [ id: %{label: "ID", sortable: true}, name: %{label: "Product Name", sortable: true, searchable: true}, sku: %{label: "SKU", sortable: true, searchable: true}, price: %{label: "Price", sortable: true, renderer: &format_price/1}, stock_quantity: %{label: "Stock", sortable: true}, active: %{label: "Status", sortable: true, renderer: &format_status/1} ] end def filters do [ active_only: Boolean.new(:active, "active", %{ label: "Active Products Only", condition: dynamic([p], p.active == true) }), price_range: Range.new(:price, "price_range", %{ type: :number, label: "Price Range", unit: "$", min: 0, max: 1000, step: 10 }), low_stock: Boolean.new(:stock_quantity, "low_stock", %{ label: "Low Stock (< 10)", condition: dynamic([p], p.stock_quantity < 10) }) ] end defp format_price(price) do assigns = %{price: price} ~H""" $<%= :erlang.float_to_binary(@price, decimals: 2) %> """ end defp format_status(active) do assigns = %{active: active} ~H""" <%= if @active, do: "Active", else: "Inactive" %> """ end end ``` -------------------------------- ### Run Project Tests Source: https://github.com/gurujada/live_table/blob/master/docs/troubleshooting.md Execute your project's test suite to verify the setup and ensure that all components are functioning as expected. This is a fundamental step in confirming a correct configuration. ```bash # Run tests to verify setup mix test ``` -------------------------------- ### Minimal LiveTable Verification - LiveView Module Source: https://github.com/gurujada/live_table/blob/master/docs/installation.md Create a minimal LiveView module to test your LiveTable installation. This example defines fields for ID and email. ```elixir defmodule YourAppWeb.TestLive do use YourAppWeb, :live_view use LiveTable.LiveResource, schema: YourApp.User def fields do [ id: %{label: "ID", sortable: true}, email: %{label: "Email", sortable: true, searchable: true} ] end def filters, do: [] end ``` -------------------------------- ### Environment-Specific Configuration (Production) Source: https://github.com/gurujada/live_table/blob/master/docs/api/table-options.md Example of Live Table configuration for the production environment, with optimized pagination, enabled exports, and a longer search debounce. ```elixir # config/prod.exs config :live_table, defaults: %{ pagination: %{ sizes: [25, 50, 100], default_size: 50 }, exports: %{ enabled: true, formats: [:csv, :pdf] }, search: %{debounce: 500} # Longer debounce for production # debug set to :off by default } ``` -------------------------------- ### Per-Table Configuration Example Source: https://github.com/gurujada/live_table/blob/master/docs/api/table-options.md Demonstrates how to override LiveTable settings for a specific table by implementing the `table_options/0` function within a LiveView module. ```APIDOC ## Per-Table Configuration Override settings for specific tables by implementing `table_options/0`: ```elixir defmodule YourAppWeb.ProductLive.Index do use YourAppWeb, :live_view use LiveTable.LiveResource, schema: YourApp.Product def table_options do %{ pagination: %{ enabled: true, sizes: [10, 25, 50] }, sorting: %{ default_sort: [name: :asc] }, mode: :table } end end ``` ``` -------------------------------- ### Environment-Specific Configuration (Development) Source: https://github.com/gurujada/live_table/blob/master/docs/api/table-options.md Example of Live Table configuration for the development environment, overriding defaults with smaller pagination and disabled exports. ```elixir # config/dev.exs config :live_table, defaults: %{ pagination: %{ sizes: [5, 10, 15], # Smaller pages for development default_size: 5 }, exports: %{enabled: false}, # Disable exports in development debug: :query # Show queries in development } ``` -------------------------------- ### Install Igniter Dependency Source: https://github.com/gurujada/live_table/blob/master/docs/generators/live_table.gen.live.md Add the `:igniter` dependency to your `mix.exs` file to use the LiveTable generator. ```elixir {:igniter, "~> 0.7", only: :dev, runtime: false} ``` -------------------------------- ### Order Report LiveView Setup Source: https://github.com/gurujada/live_table/blob/master/docs/examples/complex-queries.md Sets up a LiveView to display an order report using LiveTable. Requires `LiveTable.LiveResource` and defines data provider, fields, and filters. ```elixir defmodule YourAppWeb.OrderReportLive.Index do use YourApp, :live_view use LiveTable.LiveResource def mount(_params, _session, socket) do socket = assign(socket, :data_provider, {YourApp.Reports, :order_details, []}) {:ok, socket} end def fields do [ order_id: %{label: "Order #", sortable: true}, customer_name: %{label: "Customer", sortable: true, searchable: true}, customer_email: %{label: "Email", sortable: true, searchable: true}, product_count: %{label: "Items", sortable: true}, total_amount: %{label: "Total", sortable: true, renderer: &render_currency/1}, order_date: %{label: "Order Date", sortable: true, renderer: &render_date/1}, shipping_method: %{ label: "Shipping", sortable: true, assoc: {:shipping, :method} }, status: %{label: "Status", sortable: true, renderer: &render_status/1}, days_since_order: %{label: "Age (Days)", sortable: true, renderer: &render_days/1} ] end def filters do [ status: Select.new({:orders, :status}, "status", %{ label: "Order Status", options: [ %{label: "Pending", value: ["pending"]}, %{label: "Processing", value: ["processing"]}, %{label: "Shipped", value: ["shipped"]}, %{label: "Delivered", value: ["delivered"]} ] }), order_value: Range.new(:total_amount, "order_value", %{ type: :number, label: "Order Value", min: 0, max: 10000, step: 100 }), customer_type: Select.new({:customers, :type}, "customer_type", %{ label: "Customer Type", options: [ %{label: "Individual", value: ["individual"]}, %{label: "Business", value: ["business"]} ] }), recent_orders: Boolean.new(:order_date, "recent", %{ label: "Last 30 Days", condition: dynamic([o, customers: c, shipping: s], o.inserted_at >= ago(30, "day")) }) ] end defp render_currency(amount) do assigns = %{amount: amount} ~H""" $<.erlang.float_to_binary(@amount, decimals: 2) %> """ end defp render_date(date) do assigns = %{date: date} ~H""" <%= Calendar.strftime(@date, "%b %d, %Y") %> """ end defp render_status(status) do assigns = %{status: status} ~H""" "bg-yellow-100 text-yellow-700" "processing" -> "bg-blue-100 text-blue-700" "shipped" -> "bg-purple-100 text-purple-700" "delivered" -> "bg-green-100 text-green-700" end ]}> <%= String.Capitalize(@status) %> """ end defp render_days(days) do assigns = %{days: days} ~H""" 30, do: "text-red-600", else: "text-gray-600") ]}> <%= @days %> days """ end end ``` -------------------------------- ### User Management Filters Example Source: https://github.com/gurujada/live_table/blob/master/docs/api/filters.md An example for user management filters, including active users toggle, registration date range, role selection dropdown, and email verification status. ```elixir def filters do [ # Active users active_users: Boolean.new(:active, "active", %{ label: "Active Users Only", condition: dynamic([u], u.active == true) }), # Registration date range signup_date: Range.new(:inserted_at, "signup_range", %{ type: :date, label: "Registration Date", min: ~D[2020-01-01], max: Date.utc_today() }), # Role selection role: Select.new(:role, "role", %{ label: "User Role", options: [ %{label: "Admin", value: ["admin"]}, %{label: "Manager", value: ["manager"]}, %{label: "User", value: ["user"]}, %{label: "Guest", value: ["guest"]} ] }), # Email verified toggle verified: Boolean.new(:email_verified_at, "verified", %{ label: "Email Verified", condition: dynamic([u], not is_nil(u.email_verified_at)) }) ] end ``` -------------------------------- ### Environment-Specific Configuration (Test) Source: https://github.com/gurujada/live_table/blob/master/docs/api/table-options.md Example of Live Table configuration for the test environment, disabling pagination and search debounce for faster test execution. ```elixir # config/test.exs config :live_table, defaults: %{ pagination: %{enabled: false}, # Show all records in tests exports: %{enabled: false}, search: %{debounce: 0} # No debounce in tests # debug set to :off by default } ``` -------------------------------- ### Seed Sample Product Data Source: https://github.com/gurujada/live_table/blob/master/docs/quick-start.md Provides an example of how to seed the database with sample product data using Ecto. This is useful for testing the LiveTable implementation. ```elixir # priv/repo/seeds.exs alias YourApp.Repo alias YourApp.Catalog.Product ``` -------------------------------- ### Order Analytics Filters Example Source: https://github.com/gurujada/live_table/blob/master/docs/api/filters.md An example demonstrating filters for order analytics, including order status, order value range, order date range, high priority orders toggle, and customer type selection. ```elixir def filters do [ # Order status status: Select.new(:status, "status", %{ label: "Order Status", options: [ %{label: "Pending", value: ["pending"]}, %{label: "Processing", value: ["processing"]}, %{label: "Shipped", value: ["shipped"]}, %{label: "Delivered", value: ["delivered"]}, %{label: "Cancelled", value: ["cancelled"]} ] }), # Order value range order_total: Range.new(:total_amount, "total_range", %{ type: :number, label: "Order Total", unit: "$", min: 0, max: 10000, step: 100 }), # Date range for order placement order_date: Range.new(:inserted_at, "order_date_range", %{ type: :date, label: "Order Date", min: Date.add(Date.utc_today(), -365), max: Date.utc_today() }), # High priority orders priority_orders: Boolean.new(:priority, "priority", %{ label: "Priority Orders Only", condition: dynamic([o], o.priority in ["high", "urgent"]) }), # Customer type (for custom queries with joins) customer_type: Select.new({:customers, :type}, "customer_type", %{ label: "Customer Type", options: [ %{label: "Individual", value: ["individual"]}, %{label: "Business", value: ["business"]}, %{label: "Enterprise", value: ["enterprise"]} ] }) ] end ``` -------------------------------- ### Inspect Ecto Queries for Performance Source: https://github.com/gurujada/live_table/blob/master/docs/troubleshooting.md Inspect Ecto queries directly to understand their performance characteristics. This example shows how to convert an Ecto query to SQL for inspection. ```elixir iex> query = YourApp.Products.list_products() iex> IO.inspect(Ecto.Adapters.SQL.to_sql(:all, YourApp.Repo, query)) ``` -------------------------------- ### Live Table Per-Table Options Override Source: https://github.com/gurujada/live_table/blob/master/docs/configuration.md Define table-specific options to override global defaults. This example shows how to customize pagination sizes, default sort order, export formats, and the display mode for a specific table. ```elixir defmodule YourAppWeb.ProductLive.Index do def table_options do %{ pagination: %{sizes: [5, 15, 30]}, sorting: %{default_sort: [name: :asc]}, exports: %{formats: [:csv]}, mode: :card, card_component: &product_card/1 } end end ``` -------------------------------- ### Verify LiveTable Schema and Data Source: https://github.com/gurujada/live_table/blob/master/docs/troubleshooting.md Check your LiveTable schema configuration and ensure data exists in the database. This example shows how to verify the schema and query data using Ecto. ```elixir use LiveTable.LiveResource, schema: YourApp.Product iex> YourApp.Repo.all(YourApp.Product) |> length() ``` -------------------------------- ### Correct LiveResource Setup in LiveView Source: https://github.com/gurujada/live_table/blob/master/docs/troubleshooting.md Ensure `LiveTable.LiveResource` is used in your LiveView module for LiveTable components to render correctly. This example shows the correct setup. ```elixir defmodule YourAppWeb.ProductLive.Index do use YourAppWeb, :live_view use LiveTable.LiveResource, schema: YourApp.Product def fields do [name: %{label: "Name"}] end end ``` -------------------------------- ### Example CSV Output Source: https://github.com/gurujada/live_table/blob/master/docs/api/exports.md This is an example of the CSV data format that LiveTable can generate, including headers and sample rows. ```csv ID,Product Name,Price,Stock,Category 1,iPhone 15 Pro,999.99,25,Electronics 2,MacBook Air,1199.99,8,Electronics 3,Wireless Mouse,45.99,50,Accessories ``` -------------------------------- ### Fetch Dependencies Source: https://github.com/gurujada/live_table/blob/master/docs/installation.md After updating mix.exs, run this command to fetch the new dependency. ```bash mix deps.get ``` -------------------------------- ### Action Component Assigns Example Source: https://github.com/gurujada/live_table/blob/master/docs/api/fields.md Access the current record within an action component using the @record assign. This example shows how to display the record's name in a 'View' link. ```elixir defp view_action(assigns) do ~H""" <.link navigate={~p"/products/#{@record.id}"}> View <%= @record.name %> """ end ``` -------------------------------- ### Basic Product Table Implementation Source: https://github.com/gurujada/live_table/blob/master/docs/examples/simple-table.md Defines fields, filters, and a status renderer for a product table. Requires `LiveTable.LiveResource` and a `YourApp.Product` schema. ```elixir defmodule YourAppWeb.ProductLive.Index do use YourAppWeb, :live_view use LiveTable.LiveResource, schema: YourApp.Product def fields do [ id: %{label: "ID", sortable: true}, name: %{label: "Product Name", sortable: true, searchable: true}, price: %{label: "Price", sortable: true}, stock_quantity: %{label: "Stock", sortable: true}, active: %{label: "Status", sortable: true, renderer: &render_status/1} ] end def filters do [ active: Boolean.new(:active, "active", %{ label: "Active Products Only", condition: dynamic([p], p.active == true) }), price_range: Range.new(:price, "price_range", %{ type: :number, label: "Price Range", min: 0, max: 1000 }) ] end defp render_status(active) do assigns = %{active: active} ~H""" <%= if @active, do: "Active", else: "Inactive" %> """ end end ``` ```html
<%= @record.description %>