shadcn.io is not affiliated with official shadcn/ui
Table Footer With Totals Block for React
A timesheet table with a real footer row whose totals (hours, average rate, amount, paid and pending) are worked out from the rows shown, so a client filter changes every figure.
Installation
Overview
Add a totals row that tells the truth about what is on screen, with this table footer for React with Base UI. Nine timesheet entries over three clients sit in a native table in a fixed-height frame, with a Client Native Select above it that filters the rows. The footer is a real tfoot of one row whose cells each hold one total with its name over it: the number of entries, total hours, average rate, total amount, and how many are paid and pending. It is worked out from the rows shown on every render, in whole cents and minutes, so choosing a client changes every figure, and the polite line says the new ones. The head and the footer stay in view while the rows scroll inside the frame, each on a solid background. It's built from Native Select, Badge and Guides. For timesheets, invoices, ledgers and any table that adds up.
FAQ
How are the totals worked out?
Each entry stores its minutes and its hourly rate in cents. A helper adds the minutes and the amounts (minutes at the rate, rounded to a cent) of exactly the rows being shown, and the average rate is the amount billed divided by the hours logged, so it is weighted by time rather than a plain average of the rates. Nothing in the footer is typed.
Does the filter change the footer?
Yes. The Client select shows every entry or one client's, and the footer, the count in the line next to the select and the polite announcement are all recomputed from the filtered rows. The frame keeps its height, so the page below never moves.
What stays in view when the rows scroll?
The column heads stick at the top of the frame and the footer sticks at its foot, each on a solid background so rows never show through. When a filter leaves few rows, the footer simply follows the last row.
How is the footer built for assistive technology?
It is a tfoot row: the first cell is the row header, "Totals", and every other total sits in the cell of its own column, with its name written out above the figure ("Total hours", "Total amount"). No cell spans several columns, so a screen reader can walk the footer like any row.
How does it look on a phone?
Service and Rate go below the large breakpoint, and on a phone the client folds under the date. The footer keeps every total that still has a column, and the polite line under the select carries the rest, such as the hours and the amount for the rows shown. Nothing scrolls sideways at 320 pixels.
Related
- Pro
Sortable Members Table
Sort and searchA members table whose column heads are buttons: press one to sort, again to reverse, a third time for the original order, with aria-sort on the active head, ties settled by name and a spoken line for each result.
- Pro
Chip Filters Table
Sort and searchA bug table beside a rail of chip filters for priority and status: chips in a group are or, the groups are and, every chip counts what it would show, and an empty state clears them all.
- 1234Pro
Paginated Orders Table
Columns and pagingAn orders table of 24 rows that pages: a rows-per-page menu, the numbered pagination, a polite line saying which orders are on screen, and every page drawn once more unseen so the pager never moves.
- Pro
Row Selection Table
Select and actA stock list with a checkbox on every row, a head checkbox that shows a dash when only some are ticked, Shift-click range select and a live line that adds up the price of the ticked rows.
- Pro
Sticky Header Table
Columns and pagingA sixty-row cash ledger in a fixed-height region where the column heads and the day row stay at the top while you scroll, with a Jump to menu of weeks that scrolls the region and a band that names the day at the top.
- Pro
Compare Rows Table
Totals and comparisonA sales table where you tick up to two quarters and a band closing the panel compares them metric by metric, with the signed difference and the change as an arrow, a sign and a word, plus Swap A and B.