Lesson 3 — Expanding Table
The Table component from Module 3 handles basic column definitions
well. KanbanFlow needs more — row actions, and proper empty state
handling using the EmptyState component we just built in Lesson 2.
What we’re adding
Two additions to the existing Table component:
- Empty state — when
rowsis empty, renderEmptyStaterather than an empty table or a plain paragraph - Row actions — an optional
actionsblock that renders per-row action links in a dedicated column
The updated component
|
|
Why EmptyState rather than a plain paragraph
We built EmptyState in Lesson 2 specifically for this use case —
a collection with no records. Using it here rather than a plain p tag
keeps empty state handling consistent throughout the app. Every empty
collection looks and behaves the same way.
The title and message props on render_empty_state are hardcoded
defaults. If you need a custom empty message for a specific table, pass
it via a prop — but for most cases the defaults are fine.
Why instance_exec for actions
The actions block executes inside each row:
|
|
instance_exec(row, &@action_block) rather than @action_block.call(row)
is deliberate. instance_exec runs the block in the context of the
Table instance — which means Phlex tag methods (a, span, button
etc.) are available inside the block:
|
|
If we used @action_block.call(row) instead, the block would run in
the caller’s context — Phlex tag methods wouldn’t be available, and
a(href: ...) would raise NoMethodError.
This is the same mechanism Phlex uses internally for yield(self) — the
block runs in the component’s rendering context so all output methods
are available.
Usage
|
|
Empty rows — pass an empty array and EmptyState renders automatically:
|
|
Note on styling:
Tablecurrently uses raw Tailwind palette values (bg-gray-50,text-gray-700etc.). In Module 7 these are replaced with semantic tokens —bg-surface-alt,text-textetc. — as part of the fullPhlex::UIrestyling. The structure and behaviour are unchanged.
Lookbook preview
|
|
The empty scenario is the most important preview to check — confirm
that EmptyState renders correctly rather than an empty table structure.