@xeplr/ui-table 1.1.8 → 1.1.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -59,6 +59,7 @@ The package ships its `src/` as ES modules with JSX and imports its own styleshe
59
59
  | `toolbarLeading` | — | `(ctx) => node` after the built-in toolbar buttons |
60
60
  | `toolbarActions` | — | `(ctx) => node` replacing Clear Filters / Clear Sort |
61
61
  | `rowClassName` | — | `(row) => string` |
62
+ | `pinBottomRows` | — | `(row) => boolean` — rows kept at the **bottom of every page**, whatever is sorted, filtered or paged (a grand total: the last row of the data, which with pages was on the last page only). Drawn like any row (`rowClassName` still applies) after the page's own rows; TanStack row pinning with `keepPinnedRows` |
62
63
  | `columnClassName` | — | `(column, index) => string`, applied to the header and every cell of that column |
63
64
  | `cellStyle` | — | `({ row, rowIndex, columnKey, value }) => style` — on top of the schema's conditional styles |
64
65
  | `headerStyle` | — | `({ columnKey, isGroupHeader, depth }) => style` |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xeplr/ui-table",
3
- "version": "1.1.8",
3
+ "version": "1.1.9",
4
4
  "description": "Controlled TanStack Table wrapper with auto-detected column types and smart filters",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
@@ -186,13 +186,18 @@ export default function XeplrTable(props) {
186
186
  sorting: props.sorting,
187
187
  onSortingChange: props.onSortingChange,
188
188
  enableFiltering: props.enableFiltering,
189
- enablePagination: props.enablePagination
189
+ enablePagination: props.enablePagination,
190
+ // (row) → true for a row kept at the bottom of every page — a grand total.
191
+ pinBottomRows: props.pinBottomRows
190
192
  });
191
193
 
192
194
  var enableFiltering = props.enableFiltering !== false;
193
195
  var enablePagination = props.enablePagination !== false;
194
196
  var headerGroups = table.getHeaderGroups();
195
- var rows = table.getRowModel().rows;
197
+ // Rows the host pins to the bottom (pinBottomRows — a grand total) are
198
+ // drawn after every page's rows; the page's own rows are the rest.
199
+ var pinned = table.getBottomRows ? table.getBottomRows() : [];
200
+ var rows = pinned.length ? table.getCenterRows() : table.getRowModel().rows;
196
201
 
197
202
  // A consumer that wants a frozen header opts in with its own CSS
198
203
  // (`position: sticky; top: 0` on .xeplr-table-th) — this component has no
@@ -595,7 +600,7 @@ export default function XeplrTable(props) {
595
600
  <td className="xeplr-table-empty" colSpan={totalColumns}>No data</td>
596
601
  </tr>
597
602
  )}
598
- {rows.map(function(row) {
603
+ {rows.concat(pinned).map(function(row) {
599
604
  var original = row.original;
600
605
  var rowId = getRowId(original);
601
606
  var isSelected = actions.selectedIds.has(rowId);
package/src/pinRows.js ADDED
@@ -0,0 +1,10 @@
1
+ // WHICH ROWS ARE KEPT AT THE BOTTOM OF EVERY PAGE — `pinBottomRows(row)`
2
+ // answered for each row of `data`, as TanStack's row ids (a top-level row's
3
+ // id is its position in `data`). A grand total is the usual one: the last row
4
+ // of the data, which with pages would otherwise be on the last page only.
5
+ export function bottomRowIds(data, pinBottomRows) {
6
+ if (typeof pinBottomRows !== 'function') return [];
7
+ var ids = [];
8
+ (data || []).forEach(function (row, i) { if (pinBottomRows(row)) ids.push(String(i)); });
9
+ return ids;
10
+ }
@@ -10,6 +10,7 @@ import {
10
10
  createColumnHelper
11
11
  } from '@tanstack/react-table';
12
12
  import { detectTypes, TYPES } from './detectTypes.js';
13
+ import { bottomRowIds } from './pinRows.js';
13
14
  import { stringFilterFn } from './filters/StringFilter.jsx';
14
15
  import { numberFilterFn } from './filters/NumberFilter.jsx';
15
16
  import { dateFilterFn } from './filters/DateFilter.jsx';
@@ -155,6 +156,14 @@ export default function useTableController(options) {
155
156
  var [columnFilters, setColumnFilters] = useState([]);
156
157
  var [pagination, setPagination] = useState({ pageIndex: 0, pageSize: pageSize });
157
158
 
159
+ // ROWS KEPT AT THE BOTTOM OF EVERY PAGE (`pinBottomRows(row) → boolean`):
160
+ // a grand total is the last row of the data, so with pages it was on the
161
+ // last page only. Pinned, it is drawn under every page's rows and stays
162
+ // there whatever is sorted or filtered (TanStack row pinning,
163
+ // keepPinnedRows). By the row's position in `data`, TanStack's own id.
164
+ var pinBottomRows = options.pinBottomRows;
165
+ var bottomIds = useMemo(function () { return bottomRowIds(data, pinBottomRows); }, [data, pinBottomRows]);
166
+
158
167
  // ── TanStack table instance ──
159
168
  var table = useReactTable({
160
169
  data: data,
@@ -162,8 +171,11 @@ export default function useTableController(options) {
162
171
  state: {
163
172
  sorting: sorting,
164
173
  columnFilters: columnFilters,
165
- pagination: pagination
174
+ pagination: pagination,
175
+ rowPinning: { top: [], bottom: bottomIds }
166
176
  },
177
+ enableRowPinning: bottomIds.length > 0,
178
+ keepPinnedRows: true,
167
179
  onSortingChange: setSorting,
168
180
  onColumnFiltersChange: setColumnFilters,
169
181
  onPaginationChange: setPagination,