@jielga/tmdatagrid 2.1.4 → 2.2.0

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.
Files changed (48) hide show
  1. package/dist/index.d.ts +38 -2
  2. package/dist/index.js +1329 -1246
  3. package/dist/index.js.map +1 -1
  4. package/docs/cell-selection.md +1 -1
  5. package/docs/column-layout.md +13 -8
  6. package/docs/columns.md +57 -2
  7. package/docs/export.md +2 -2
  8. package/docs/filtering.md +105 -15
  9. package/docs/getting-started.md +40 -0
  10. package/docs/grouping.md +9 -6
  11. package/docs/loading-and-empty.md +29 -9
  12. package/docs/localization.md +130 -3
  13. package/docs/menu.md +1 -1
  14. package/docs/pagination.md +26 -7
  15. package/docs/row-details.md +36 -4
  16. package/docs/row-interaction.md +1 -1
  17. package/docs/row-selection.md +6 -7
  18. package/docs/scrolling.md +1 -1
  19. package/docs/server-side.md +3 -1
  20. package/docs/testing.md +18 -0
  21. package/docs/use-tm-data-grid.md +69 -34
  22. package/package.json +1 -1
  23. package/skills/appearance/SKILL.md +6 -4
  24. package/skills/appearance/references/labels.md +126 -0
  25. package/skills/cell-selection/SKILL.md +2 -2
  26. package/skills/columns/SKILL.md +42 -41
  27. package/skills/columns/references/columns-api.md +15 -1
  28. package/skills/data/SKILL.md +77 -50
  29. package/skills/editing/SKILL.md +1 -1
  30. package/skills/filtering/SKILL.md +71 -49
  31. package/skills/filtering/references/custom-filters.md +118 -0
  32. package/skills/getting-started/SKILL.md +37 -2
  33. package/skills/grouping/SKILL.md +16 -9
  34. package/skills/migrating-to-2/SKILL.md +1 -1
  35. package/skills/options/SKILL.md +131 -51
  36. package/skills/rows/SKILL.md +53 -31
  37. package/skills/server-side/SKILL.md +1 -1
  38. package/skills/testing/SKILL.md +12 -1
  39. package/skills/testing-components/SKILL.md +1 -1
  40. package/skills/testing-editing/SKILL.md +1 -1
  41. package/src/components/TMDataGridTable.tsx +241 -41
  42. package/src/core/autosize.ts +19 -7
  43. package/src/core/cellRange.ts +11 -2
  44. package/src/core/colSpan.ts +78 -0
  45. package/src/core/columnUtils.ts +7 -0
  46. package/src/core/filterOperators.ts +16 -1
  47. package/src/index.ts +4 -0
  48. package/src/useTMDataGrid.tsx +38 -0
@@ -1,10 +1,11 @@
1
1
  import type {
2
2
  ColumnFiltersState,
3
+ FilterMeta,
3
4
  Row,
4
5
  RowData,
5
6
  TableFeatures,
6
7
  } from "@tanstack/react-table";
7
- import type { TMDataGridTable } from "../useTMDataGrid";
8
+ import type { TMDataGridFeatures, TMDataGridTable } from "../useTMDataGrid";
8
9
 
9
10
  /**
10
11
  * The value shape stored in `columnFilters` for every TMDataGrid column.
@@ -474,6 +475,20 @@ export function matchesFilter(
474
475
  }
475
476
  }
476
477
 
478
+ /**
479
+ * The signature of a column's own `filterFn`. The third argument is the
480
+ * `{ operator, value }` envelope the grid writes into `columnFilters`; a
481
+ * column `filterFn` replaces `tmDataGridFilterFn` outright, so it is handed
482
+ * the envelope, not the unwrapped value. Delegate to `tmDataGridFilterFn`
483
+ * for the operators the function does not handle itself.
484
+ */
485
+ export type TMDataGridFilterFn<TData extends RowData> = (
486
+ row: Row<TMDataGridFeatures, TData>,
487
+ columnId: string,
488
+ filterValue: TMDataGridFilterValue,
489
+ addMeta?: (meta: FilterMeta) => void,
490
+ ) => boolean;
491
+
477
492
  /**
478
493
  * The single filter function every TMDataGrid column uses. It dispatches on the
479
494
  * operator carried by the filter value, which is what lets one column offer
package/src/index.ts CHANGED
@@ -16,6 +16,7 @@ export {
16
16
  openColumnFilter,
17
17
  type TMDataGridApi,
18
18
  type TMDataGridColumnMeta,
19
+ type TMDataGridColSpanArgs,
19
20
  type TMDataGridDetailsArgs,
20
21
  type TMDataGridDetailsRenderer,
21
22
  type TMDataGridFeatures,
@@ -50,6 +51,7 @@ export type {
50
51
  export {
51
52
  type TMDataGridColumnFilter,
52
53
  type TMDataGridColumnType,
54
+ type TMDataGridFilterFn,
53
55
  type TMDataGridFilterOperator,
54
56
  type TMDataGridFilterValue,
55
57
  type TMDataGridFilterValueShape,
@@ -60,9 +62,11 @@ export {
60
62
  formatFilterLabel,
61
63
  getOperatorsForType,
62
64
  isFilterActive,
65
+ matchesFilter,
63
66
  operatorNeedsValue,
64
67
  operatorTakesArrayValue,
65
68
  operatorTakesRangeValue,
69
+ tmDataGridFilterFn,
66
70
  } from "./core/filterOperators";
67
71
  export {
68
72
  fuzzyGlobalFilterFn,
@@ -79,6 +79,7 @@ import {
79
79
  tmDataGridFilterFn,
80
80
  } from "./core/filterOperators";
81
81
  import {
82
+ DEFAULT_COLUMN_MIN_SIZE,
82
83
  getColumnDefaultOperator,
83
84
  isControlColumn,
84
85
  isGeneratedColumn,
@@ -194,6 +195,28 @@ export type TMDataGridColumnMeta<TData extends RowData = TMDataGridRowData> = {
194
195
  /** Share of the leftover width this column claims. Defaults to `1`. */
195
196
  flex?: number;
196
197
  align?: "left" | "right" | "center";
198
+ /**
199
+ * How many columns this column's cell covers on a row, counting itself.
200
+ * Defaults to `1`.
201
+ *
202
+ * A cell spanning `n` is one cell `n` columns wide; the `n - 1` cells to its
203
+ * right do not render on that row. A function decides per row:
204
+ *
205
+ * ```tsx
206
+ * meta: {
207
+ * // An open row's title takes the rest of the row.
208
+ * colSpan: ({ row }) => (row.getIsExpanded() ? Infinity : 1),
209
+ * }
210
+ * ```
211
+ *
212
+ * Counted over the displayed columns, so hiding or moving a column changes
213
+ * what a span covers. A span stops at the last of your columns - it never
214
+ * covers the checkbox, tree, details or edit lane - and at the edge of its
215
+ * pinned block. Group rows, and a row open in row edit mode, ignore it.
216
+ *
217
+ * Display only: sorting, filtering, copy and export still see every column.
218
+ */
219
+ colSpan?: number | ((args: TMDataGridColSpanArgs<TData>) => number);
197
220
  /**
198
221
  * Size the column to its widest mounted content once, after the first rows
199
222
  * render - unless a persisted or user-set width already covers it. The same
@@ -385,6 +408,12 @@ export type TMDataGridDetailsArgs<TData extends RowData> = {
385
408
  table: TMDataGridTable<TData>;
386
409
  };
387
410
 
411
+ /** What a `meta.colSpan` function receives. */
412
+ export type TMDataGridColSpanArgs<TData extends RowData> = {
413
+ row: Row<TMDataGridFeatures, TData>;
414
+ table: TMDataGridTable<TData>;
415
+ };
416
+
388
417
  /** Builds the panel shown underneath an expanded row. See `renderDetails`. */
389
418
  export type TMDataGridDetailsRenderer<TData extends RowData> = (
390
419
  args: TMDataGridDetailsArgs<TData>,
@@ -1556,6 +1585,14 @@ export function useTMDataGrid<TData extends RowData>({
1556
1585
  () => tableRef.current as unknown as TMDataGridQueryTable,
1557
1586
  [],
1558
1587
  );
1588
+ // The grid's `minSize` floor under the consumer's `defaultColumn`, which
1589
+ // still wins per key. Keyed on the consumer's object, because TanStack
1590
+ // memoizes the default column def on `options.defaultColumn` identity.
1591
+ const consumerDefaultColumn = options.defaultColumn;
1592
+ const defaultColumn = useMemo(
1593
+ () => ({ minSize: DEFAULT_COLUMN_MIN_SIZE, ...consumerDefaultColumn }),
1594
+ [consumerDefaultColumn],
1595
+ );
1559
1596
 
1560
1597
  // The sync of `state` into the table's atoms happens inside this call, in
1561
1598
  // the render body, and publishing from there makes React warn about the
@@ -1624,6 +1661,7 @@ export function useTMDataGrid<TData extends RowData>({
1624
1661
  ) as TableOptions<TMDataGridFeatures, TData>["onGroupingChange"],
1625
1662
  }
1626
1663
  : {}),
1664
+ defaultColumn,
1627
1665
  // The rows as shown - see `shown` above. The consumer's own array passes
1628
1666
  // through untouched while nothing is committed.
1629
1667
  data: shown.rows,