Data presentation and browsing
Data presentation and browsing gives users clear ways to scan records, follow trends, move through large result sets, and understand loading or completion. The components share a server-rendered model that can show current data at once or preserve browsing choices as users sort, search, filter, select, and change pages. For the related data-table, chart and paging, and hierarchical browsing views, see Data tables, Charts, paging, and progress, and Hierarchical data and manipulation.
Presentation surfaces
The library offers different surfaces for different amounts and shapes of data. A plain table suits a small set of records, a data table adds a full browse cycle, and visual components reduce a trend or value to a quick signal.
Tabular records
PetalComponents.Table is the basic record view. It accepts rows and column slots, then adds common table behavior such as empty content, totals, row actions, row clicks, sortable headers, compact density, stripes, and a sticky header. It does not choose how an application loads or changes the rows.
PetalComponents.DataTable builds on that table for result sets that need a toolbar, filters, search, selection, column controls, loading rows, a result range, and page controls. Its typed column filters use a shared editor and URL format, so link-mode controls and event-mode forms describe the same filter state. It keeps the visual shape consistent while the owning LiveView supplies the current rows and browsing state.
See Data tables for the data table state, rendering contract, and browser behavior.
References: lib/…/table.ex• L6-73 lib/…/table.ex• L83-158 lib/…/data_table.ex• L1-56 lib/…/data_table.ex• L242-317 lib/…/filter_editor.ex• L1-25
Visual summaries
PetalComponents.Chart presents a larger chart from a server-side option map. The browser draws it through ECharts, so a change to the data that feeds the option can update the chart in place. PetalComponents.Sparkline serves the smaller case: it shows an inline trend as an SVG and needs no browser code.
PetalComponents.NumberTicker adds motion to a single changing value. The final value remains in the server-rendered markup, so the metric still has useful content when its browser animation is not available.
See Charts, paging, and progress for the visual components and their update behavior.
References: lib/…/chart.ex• L1-9 lib/…/chart.ex• L114-137 lib/…/sparkline.ex• L1-9 lib/…/sparkline.ex• L27-60 lib/…/number_ticker.ex• L1-9 lib/…/number_ticker.ex• L36-62
Browsing state
The data table separates the state that changes the result set from the state that changes only its presentation. This split lets an application put useful queries in the URL while keeping local display choices and selected records out of the query.
Query state
PetalComponents.DataTable.State is the shared description of a result query. It carries sort order, filters, quick search, page number, page size, and the known result total. Filter editors express text, number, date, option, choice, and boolean values through the same state contract. A query engine consumes that state and returns the visible rows together with the total needed by the footer and pagination.
The component supports two ways to send a change back to the owning LiveView:
| Wiring | State path | Best fit |
|---|---|---|
| Link mode | Sorts, filters, search, and pages become patched URL parameters. | Shareable searches, browser history, and normal page navigation. |
| Event mode | Each action sends one operation payload to the LiveView. | A custom query process or a view that owns all changes through events. |
The same user action therefore has two transport choices without changing the table's visible behavior. Sort, search, filter, and page-size changes return to the first page because the old page may no longer exist in the new result set.
The flow below shows how a user action becomes new state and new visible data.
flowchart LR
U[User changes sort search filter or page] --> T[Data table action]
T --> W[URL patch or LiveView event]
W --> S[Query state]
S --> Q[Query engine or application query]
Q --> R[Visible rows and result total]
R --> T
References: lib/…/state.ex• L1-20 lib/…/state.ex• L146-199 lib/…/state.ex• L201-250 lib/…/data_table.ex• L7-31 lib/…/data_table.ex• L863-899 lib/…/filter_editor.ex• L16-25 lib/…/list.ex• L1-15
Presentation state
Selection and column layout are presentation choices rather than query choices. Selected row IDs, hidden columns, and column order travel through UI events in either wiring mode, so a user can keep a selection while moving between pages without changing the URL.
This behavior depends on clear identity. A row ID must identify a record across the full data set, not only on the current page. A unique record key is suitable; a value shown to users is safe only when the application guarantees that it is unique.
References: lib/…/data_table.ex• L33-44 lib/…/data_table.ex• L141-207 lib/…/data_table.ex• L748-785
Paging and loading
Paging limits the amount of data a user must scan at one time. Loading components keep the shape of the page stable while data is not ready, and progress components show known work instead of pretending that an unknown duration has a percentage.
Page navigation
PetalComponents.Pagination presents either a numbered page window or a simple Previous/Next pair. It can create normal links, LiveView patches or redirects, or event buttons. The data table uses numbered navigation when it knows the total page count and simple navigation when the data source reports an unknown total.
The control keeps page targets within a valid range even when a total or current page is missing or outside that range. In event mode, page actions can use the data table's named change event and carry extra operation values. In link mode, the control can derive each destination from a page path or path function.
When a total is known, the data table also shows the visible range and total result count. When the total is unknown, it reports the current page and uses the simple form so the interface does not claim more knowledge than the data source provides.
References: lib/…/pagination.ex• L1-4 lib/…/pagination.ex• L12-121 lib/…/pagination.ex• L124-203 lib/…/pagination.ex• L231-261 lib/…/data_table.ex• L592-636 lib/…/state.ex• L353-360
Loading signals
PetalComponents.Skeleton supplies neutral placeholders for content that is still loading. The data table uses text-shaped skeleton rows in place of records, which keeps column widths and the main table shape visible during a query.
PetalComponents.Progress is for known progress. Its bar and ring share a value and maximum, while a status line can announce changing work to assistive technology. A missing value has no percentage to report, so use an indeterminate loading signal rather than presenting a false number.
References: lib/…/skeleton.ex• L1-22 lib/…/skeleton.ex• L49-64 lib/…/skeleton.ex• L372-415 lib/…/data_table.ex• L499-589 lib/…/progress.ex• L1-26 lib/…/progress.ex• L41-67 lib/…/progress.ex• L281-327
Composition boundaries
These components fit together at a few clear boundaries. The application owns data and query work, the presentation components own the user-facing shape, and the browser hooks add motion or small client-side actions where server-rendered markup cannot do the work alone.
| Boundary | Responsibility |
|---|---|
| Application data source | Supplies rows and applies the query state. It may use the in-memory list path for small data or its own query layer for larger data. |
| Presentation component | Renders records, charts, metrics, page controls, empty states, and loading states from current assigns. |
| LiveView state | Decides whether query changes use URL parameters or events. It also owns selection and column layout state. |
| Browser enhancement | Draws ECharts charts, animates number changes, and supports data-table controls that need DOM state. |
This boundary keeps the visual components reusable. A change in the source data can update a table or chart without requiring a new presentation pattern, while a change in the browse contract must remain consistent across the state, query source, and controls.
References: lib/…/data_table.ex• L46-49 lib/…/data_table.ex• L287-315 lib/…/chart.ex• L20-29 lib/…/number_ticker.ex• L7-9
Change checklist
When these files or sections are changed, remember to consider these:
- Keep the data table operation names aligned between
State.handle_op/3, event-mode controls, and any LiveView handlers. - Keep filter editor shapes, form field names, and URL encoding aligned between
DataTable.FilterEditor, the browser hook, and state decoding. - Keep the field whitelist and the query source aligned so a sort or filter shown in the UI can be applied by the data source.
- Keep row identity stable across pages when selection can remain active during paging.
- Preserve the distinction between a known total and an unknown total when changing pagination or range text.
- Keep pagination event names and extra event values aligned with the LiveView operation grammar.
- Keep page-path generation consistent when changing the page placeholder or allowing function-based paths.
- When changing chart updates or chart options, keep the consuming ECharts asset and browser hook contract valid.
- Keep loading markup and status announcements separate from decorative skeleton motion and chart animation.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| A data table has neither a path nor a change event. | It cannot send sort, filter, or page changes. | Select link mode or event mode when the table is wired. |
| A filter editor and its state decoder use different value shapes. | A filter can display one value but query another value or fail to round-trip from the URL. | Keep typed editor fields and the shared filter encoding contract together. |
| A selected row ID is not unique across the data set. | Selection can point to the wrong record or fail on duplicate IDs on one page. | Use a stable record key for row_id. |
| The query has no stable tie-breaker for equal sort values. | Rows can move between pages as the same query runs again. | Add a unique tie-breaker when building the application state. |
| A page event name or event values do not match the LiveView handler. | Pagination clicks reach the view but do not update the result set. | Keep pagination event wiring and the operation grammar aligned. |
| A path does not contain a supported page placeholder or returns an invalid destination. | Link-mode controls point to the wrong page or cannot navigate. | Use a page path with the expected placeholder or a path function that returns a valid destination. |
| A chart is rendered without an ECharts runtime. | The chart surface cannot draw its option. | Add ECharts to the consuming application before using the chart. |
| A sparkline receives fewer than two numeric points. | Its trend path cannot be formed. | Supply at least two numeric points. |
| An unknown-duration task is shown as a percentage. | Users receive a false progress value. | Use a loading signal until a real value and maximum exist. |
Key files
| File | Why to read it |
|---|---|
lib/petal_components/data_table.ex | Primary composition point for table records, controls, loading rows, selection, and page navigation. |
lib/petal_components/data_table/filter_editor.ex | Defines the shared typed filter controls, displayed predicates, and link-mode filter encoding. |
lib/petal_components/data_table/state.ex | Defines the query state and the URL and event contract used by stateful browsing. |
lib/petal_components/data_table/engine/list.ex | Shows the complete small-data path from search and filters to sorted, paged rows. |
lib/petal_components/table.ex | Defines the reusable table surface and its column, empty, footer, and row interaction slots. |
lib/petal_components/pagination.ex | Defines numbered and simple page navigation with link and event modes. |
lib/petal_components/chart.ex | Defines full charts, live option updates, and the ECharts boundary. |
lib/petal_components/sparkline.ex | Defines compact inline trend presentation without JavaScript. |
lib/petal_components/progress.ex | Defines known-progress bars and rings with accessible value signals. |
lib/petal_components/skeleton.ex | Defines loading placeholders and their loading-region accessibility model. |
lib/petal_components/number_ticker.ex | Defines animated metric values with a server-rendered fallback. |