@mini_7/material-react-table-mcp 4.0.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 (170) hide show
  1. package/README.md +68 -0
  2. package/data/MIGRATION.md +136 -0
  3. package/data/api.json +5379 -0
  4. package/data/examples/advanced.tsx +309 -0
  5. package/data/examples/aggregation-and-grouping.tsx +153 -0
  6. package/data/examples/aggregation-multi.tsx +105 -0
  7. package/data/examples/alternate-column-filtering.tsx +49 -0
  8. package/data/examples/alternate-detail-panel.tsx +81 -0
  9. package/data/examples/alternate-pagination.tsx +23 -0
  10. package/data/examples/basic.tsx +109 -0
  11. package/data/examples/chart-detail-panel.tsx +89 -0
  12. package/data/examples/column-actions-space.tsx +44 -0
  13. package/data/examples/column-alignment.tsx +70 -0
  14. package/data/examples/custom-column-actions.tsx +109 -0
  15. package/data/examples/custom-column-filtering-ui.tsx +89 -0
  16. package/data/examples/custom-headless.tsx +125 -0
  17. package/data/examples/custom-top-toolbar.tsx +88 -0
  18. package/data/examples/customize-display-columns.tsx +85 -0
  19. package/data/examples/customize-filter-components.tsx +101 -0
  20. package/data/examples/customize-filter-modes.tsx +73 -0
  21. package/data/examples/customize-filter-variants.tsx +116 -0
  22. package/data/examples/customize-global-filter-component.tsx +52 -0
  23. package/data/examples/customize-remove-column-grouping.tsx +94 -0
  24. package/data/examples/customize-row-selection.tsx +54 -0
  25. package/data/examples/customize-table-styles.tsx +100 -0
  26. package/data/examples/disable-column-actions.tsx +37 -0
  27. package/data/examples/disable-column-hiding.tsx +90 -0
  28. package/data/examples/disable-density-toggle.tsx +49 -0
  29. package/data/examples/dynamic-columns.tsx +189 -0
  30. package/data/examples/editing-crud-cell.tsx +377 -0
  31. package/data/examples/editing-crud-modal.tsx +370 -0
  32. package/data/examples/editing-crud-row.tsx +333 -0
  33. package/data/examples/editing-crud-table.tsx +369 -0
  34. package/data/examples/editing-crud-tree.tsx +416 -0
  35. package/data/examples/enable-cell-actions.tsx +76 -0
  36. package/data/examples/enable-click-to-copy.tsx +39 -0
  37. package/data/examples/enable-column-grouping.tsx +120 -0
  38. package/data/examples/enable-column-ordering.tsx +48 -0
  39. package/data/examples/enable-column-pinning.tsx +69 -0
  40. package/data/examples/enable-column-resizing.tsx +56 -0
  41. package/data/examples/enable-column-virtualization.tsx +27 -0
  42. package/data/examples/enable-detail-panel-conditionally.tsx +78 -0
  43. package/data/examples/enable-detail-panel-virtualized.tsx +80 -0
  44. package/data/examples/enable-expanding-tree.tsx +110 -0
  45. package/data/examples/enable-filter-facet-values.tsx +65 -0
  46. package/data/examples/enable-row-dragging.tsx +137 -0
  47. package/data/examples/enable-row-numbers-original.tsx +48 -0
  48. package/data/examples/enable-row-numbers-static.tsx +48 -0
  49. package/data/examples/enable-row-ordering.tsx +57 -0
  50. package/data/examples/enable-row-pinning-select.tsx +76 -0
  51. package/data/examples/enable-row-pinning-static.tsx +50 -0
  52. package/data/examples/enable-row-pinning-sticky.tsx +69 -0
  53. package/data/examples/enable-row-selection.tsx +96 -0
  54. package/data/examples/enable-row-virtualization.tsx +101 -0
  55. package/data/examples/enable-sticky-header.tsx +59 -0
  56. package/data/examples/expanding-tree-expanded.tsx +121 -0
  57. package/data/examples/expanding-tree-flat-parse.tsx +125 -0
  58. package/data/examples/expanding-tree-root-expanded.tsx +151 -0
  59. package/data/examples/export-to-csv.tsx +114 -0
  60. package/data/examples/export-to-pdf.tsx +104 -0
  61. package/data/examples/external-toolbar.tsx +108 -0
  62. package/data/examples/font-awesome-icons.tsx +106 -0
  63. package/data/examples/infinite-scrolling.tsx +208 -0
  64. package/data/examples/lazy-detail-panel.tsx +262 -0
  65. package/data/examples/lazy-sub-rows.tsx +190 -0
  66. package/data/examples/linear-progress.tsx +66 -0
  67. package/data/examples/loading.tsx +50 -0
  68. package/data/examples/localization-i18n-ar.tsx +65 -0
  69. package/data/examples/localization-i18n-az.tsx +60 -0
  70. package/data/examples/localization-i18n-bg.tsx +60 -0
  71. package/data/examples/localization-i18n-cs.tsx +60 -0
  72. package/data/examples/localization-i18n-da.tsx +60 -0
  73. package/data/examples/localization-i18n-de.tsx +60 -0
  74. package/data/examples/localization-i18n-el.tsx +60 -0
  75. package/data/examples/localization-i18n-en.tsx +60 -0
  76. package/data/examples/localization-i18n-es.tsx +60 -0
  77. package/data/examples/localization-i18n-et.tsx +60 -0
  78. package/data/examples/localization-i18n-fa.tsx +66 -0
  79. package/data/examples/localization-i18n-fi.tsx +60 -0
  80. package/data/examples/localization-i18n-fr.tsx +60 -0
  81. package/data/examples/localization-i18n-he.tsx +66 -0
  82. package/data/examples/localization-i18n-hr.tsx +60 -0
  83. package/data/examples/localization-i18n-hu.tsx +60 -0
  84. package/data/examples/localization-i18n-hy.tsx +65 -0
  85. package/data/examples/localization-i18n-id.tsx +60 -0
  86. package/data/examples/localization-i18n-it.tsx +60 -0
  87. package/data/examples/localization-i18n-ja.tsx +60 -0
  88. package/data/examples/localization-i18n-ko.tsx +60 -0
  89. package/data/examples/localization-i18n-nl.tsx +60 -0
  90. package/data/examples/localization-i18n-no.tsx +60 -0
  91. package/data/examples/localization-i18n-np.tsx +60 -0
  92. package/data/examples/localization-i18n-pl.tsx +60 -0
  93. package/data/examples/localization-i18n-pt-BR.tsx +60 -0
  94. package/data/examples/localization-i18n-pt.tsx +60 -0
  95. package/data/examples/localization-i18n-ro.tsx +60 -0
  96. package/data/examples/localization-i18n-ru.tsx +60 -0
  97. package/data/examples/localization-i18n-sk.tsx +60 -0
  98. package/data/examples/localization-i18n-sr-Cyrl-RS.tsx +60 -0
  99. package/data/examples/localization-i18n-sr-Latn-RS.tsx +60 -0
  100. package/data/examples/localization-i18n-sv.tsx +60 -0
  101. package/data/examples/localization-i18n-tr.tsx +60 -0
  102. package/data/examples/localization-i18n-uk.tsx +60 -0
  103. package/data/examples/localization-i18n-vi.tsx +60 -0
  104. package/data/examples/localization-i18n-zh-hans.tsx +60 -0
  105. package/data/examples/localization-i18n-zh-hant.tsx +60 -0
  106. package/data/examples/manual-selection.tsx +105 -0
  107. package/data/examples/minimal.tsx +78 -0
  108. package/data/examples/mui-theme.tsx +136 -0
  109. package/data/examples/multi-sorting.tsx +58 -0
  110. package/data/examples/persistent-state.tsx +184 -0
  111. package/data/examples/react-query.tsx +182 -0
  112. package/data/examples/remote.tsx +150 -0
  113. package/data/examples/row-actions-buttons.tsx +89 -0
  114. package/data/examples/row-actions-menu-items.tsx +64 -0
  115. package/data/examples/single-row-selection.tsx +98 -0
  116. package/data/examples/virtualized.tsx +138 -0
  117. package/data/guides/accessibility.md +119 -0
  118. package/data/guides/aggregation.md +210 -0
  119. package/data/guides/async-loading.md +132 -0
  120. package/data/guides/best-practices.md +363 -0
  121. package/data/guides/cell-actions.md +139 -0
  122. package/data/guides/click-to-copy.md +67 -0
  123. package/data/guides/column-actions.md +69 -0
  124. package/data/guides/column-filtering.md +366 -0
  125. package/data/guides/column-grouping.md +192 -0
  126. package/data/guides/column-hiding.md +133 -0
  127. package/data/guides/column-ordering-dnd.md +99 -0
  128. package/data/guides/column-pinning.md +72 -0
  129. package/data/guides/column-resizing.md +157 -0
  130. package/data/guides/column-size.md +162 -0
  131. package/data/guides/customize-components.md +395 -0
  132. package/data/guides/customize-icons.md +35 -0
  133. package/data/guides/data-columns.md +292 -0
  134. package/data/guides/density-toggle.md +46 -0
  135. package/data/guides/detail-panel.md +195 -0
  136. package/data/guides/display-columns.md +135 -0
  137. package/data/guides/editing.md +367 -0
  138. package/data/guides/expanding-sub-rows.md +194 -0
  139. package/data/guides/full-screen-toggle.md +63 -0
  140. package/data/guides/global-filtering.md +237 -0
  141. package/data/guides/localization.md +57 -0
  142. package/data/guides/memoization.md +157 -0
  143. package/data/guides/pagination.md +171 -0
  144. package/data/guides/row-actions.md +116 -0
  145. package/data/guides/row-numbers.md +24 -0
  146. package/data/guides/row-ordering-dnd.md +51 -0
  147. package/data/guides/row-pinning.md +96 -0
  148. package/data/guides/row-selection.md +237 -0
  149. package/data/guides/sorting.md +190 -0
  150. package/data/guides/state-management.md +165 -0
  151. package/data/guides/sticky-header.md +41 -0
  152. package/data/guides/table-event-listeners.md +103 -0
  153. package/data/guides/toolbar-customization.md +251 -0
  154. package/data/guides/virtualization.md +183 -0
  155. package/data/index.json +1930 -0
  156. package/data/reference/mrt-components.md +183 -0
  157. package/data/reference/mrt-hooks.md +125 -0
  158. package/data/skills/composable-components/SKILL.md +189 -0
  159. package/data/skills/customization/SKILL.md +190 -0
  160. package/data/skills/drag-and-drop-ordering/SKILL.md +227 -0
  161. package/data/skills/editing/SKILL.md +243 -0
  162. package/data/skills/filtering/SKILL.md +213 -0
  163. package/data/skills/getting-started/SKILL.md +213 -0
  164. package/data/skills/localization/SKILL.md +182 -0
  165. package/data/skills/migrate-v3-to-v4/SKILL.md +161 -0
  166. package/data/skills/state-and-server-data/SKILL.md +200 -0
  167. package/data/skills/virtualization/SKILL.md +203 -0
  168. package/dist/data.js +137 -0
  169. package/dist/index.js +232 -0
  170. package/package.json +50 -0
@@ -0,0 +1,133 @@
1
+ ## Column Hiding Feature Guide
2
+
3
+ The column hiding feature is enabled by default and allows the user to hide data columns from either the column actions menu or the show/hide columns menu.
4
+
5
+ ### Relevant Table Options
6
+
7
+ Relevant table options (get_mrt_api has full details):
8
+
9
+ - `enableHiding` - type `boolean` - default `true`
10
+ - `onColumnVisibilityChange` - type `OnChangeFn<ColumnVisibilityState>` - If provided, this function will be called with an updaterFn when state.columnVisibility changes. This overrides the default internal state management, so you will need to persist the state change either fully or partially outside of the table.
11
+
12
+ ### Relevant Column Options
13
+
14
+ Relevant column options (get_mrt_api has full details):
15
+
16
+ - `enableHiding` - type `boolean`
17
+ - `visibleInShowHideMenu` - type `boolean` - default `true` - Set to false if you want to hide a column from the show/hide menu.
18
+
19
+ ### Relevant State
20
+
21
+ Relevant state options (get_mrt_api has full details):
22
+
23
+ - `columnVisibility` - type `Record<string, boolean>` - default `{}` - an object mapping column IDs to a boolean indicating whether the column is currently visible
24
+
25
+ ### Hide Some Columns by Default
26
+
27
+ You can easily hide columns by default by setting the `columnVisibility` `state` or `initialState` to hide the desired columns by id.
28
+
29
+ ```jsx
30
+ const table = useMaterialReactTable({
31
+ columns,
32
+ data,
33
+ initialState: { columnVisibility: { firstName: false } }, //hide firstName column by default
34
+ });
35
+
36
+ return <MaterialReactTable table={table} />;
37
+ ```
38
+
39
+ ### Dynamically Hide Columns
40
+
41
+ If you need to control how the columns are hidden dynamically, you can use `state` instead of `initialState` along with the `onColumnVisibilityChange` table option. Or alternatively you can use the `setColumnVisibility` table instance api.
42
+
43
+ ```jsx
44
+ const [columnVisibility, setColumnVisibility] = useState({
45
+ firstName: false,
46
+ });
47
+
48
+ useEffect(() => {
49
+ setColumnVisibility({ firstName: true }); //programmatically show firstName column
50
+ }, [someDependency]);
51
+
52
+ const table = useMaterialReactTable({
53
+ columns,
54
+ data,
55
+ state: { columnVisibility }, //manage columnVisibility state
56
+ onColumnVisibilityChange: setColumnVisibility,
57
+ });
58
+
59
+ //NOTE: Instead of managing the columnVisibility state yourself, we could call a table instance api
60
+ table.setColumnVisibility({ firstName: true }); //programmatically show firstName column
61
+ ```
62
+
63
+ ### Disable Column Hiding
64
+
65
+ If you do not want this feature to be enabled at all, you can disable it by setting the `enableHiding` table option to `false`.
66
+
67
+ ```jsx
68
+ const table = useMaterialReactTable({
69
+ columns,
70
+ data,
71
+ enableHiding: false,
72
+ });
73
+ ```
74
+
75
+ Alternatively, you can disable hiding specific columns by setting the `enableHiding` column option to `false` per column.
76
+
77
+ If you want to hide certain columns by default, you can specify column visibility in the `initialState.columnVisibility` table option.
78
+
79
+ > Live example: `disable-column-hiding` (call get_mrt_example with that id).
80
+
81
+ ### Enable Column Hiding on Display Columns
82
+
83
+ By default, column hiding is only enabled on data columns. Display columns, such as `mrt-row-numbers`, `mrt-row-select`, etc., do not have column hiding enabled, and their toggle will be disabled. You can turn that back on by setting the `enableHiding` option to `true` in the `displayColumnsOptions` table option.
84
+
85
+ ```jsx
86
+ const table = useMaterialReactTable({
87
+ columns,
88
+ data,
89
+ displayColumnDefOptions: {
90
+ 'mrt-row-numbers': {
91
+ enableHiding: true, //now row numbers are hidable too
92
+ },
93
+ },
94
+ });
95
+ ```
96
+
97
+ See the [Display Columns Feature Guide](/docs/guides/display-columns#display-column-definition-options-prop) for a more in depth explanation of the `displayColumnsOptions` table option.
98
+
99
+ ### Hide Column From Show Hide Menu
100
+
101
+ > New in v2.3.0
102
+
103
+ By default, all columns are visible in the column show hide menu that is opened from the columns button in the toolbar internal actions button. You can hide a column from this menu by setting the `visibleInShowHideMenu` column option to `false`.
104
+
105
+ ```jsx
106
+ const columns = [
107
+ {
108
+ accessorKey: 'uuid',
109
+ header: 'UUID',
110
+ visibleInShowHideMenu: false, //hide this column from the show hide menu, but still show the column in the table
111
+ },
112
+ ];
113
+
114
+ const table = useMaterialReactTable({
115
+ columns,
116
+ data,
117
+ displayColumnDefOptions: {
118
+ 'mrt-row-actions': {
119
+ visibleInShowHideMenu: false, //hide the built-in row actions column from the show hide menu
120
+ },
121
+ },
122
+ });
123
+ ```
124
+
125
+ ### Custom Columns Menu
126
+
127
+ The `MRT_ShowHideColumnsMenu` component is one of the few MRT components that is pretty opinionated and not easily customizable. Instead of trying to customize the menu with overrides, it might be easier for you to just build your own new button and menu from scratch using the Table and Column Instance APIs.
128
+
129
+ Adding your own Toolbar Buttons is covered in the [Toolbar Guide](/docs/guides/toolbar-customization#customize-built-in-internal-toolbar-button-area)
130
+
131
+ If all you want to do is customize the buttons above the columns menu, you can import and use the `MRT_ShowHideColumnsMenuItems` component from material react table, which is a component that renders the columns in the list with the toggle switches, but then render your own buttons in the top or bottom of the menu itself.
132
+
133
+ View Extra Storybook **[Examples](https://www.material-react-table.dev/?path=/story/features-column-hiding-examples)**
@@ -0,0 +1,99 @@
1
+ ## Column Ordering (DnD) Feature Guide
2
+
3
+ Whether you just want to change the default column order in your table or let columns be reordered by dragging and dropping, Material React Table has a simple API for this.
4
+
5
+ ### Relevant Table Options
6
+
7
+ Relevant table options (get_mrt_api has full details):
8
+
9
+ - `enableColumnDragging` - type `boolean` - default `false`
10
+ - `enableColumnOrdering` - type `boolean`
11
+ - `onColumnOrderChange` - type `OnChangeFn<ColumnOrderState>` - If provided, this function will be called with an updaterFn when state.columnOrder changes. This overrides the default internal state management, so you will need to persist the state change either fully or partially outside of the table.
12
+ - `onDraggingColumnChange` - type `OnChangeFn<MRT_Column<TData> | null>`
13
+ - `onHoveredColumnChange` - type `OnChangeFn<MRT_Column<TData> | null>`
14
+
15
+ ### Relevant Column Options
16
+
17
+ Relevant column options (get_mrt_api has full details):
18
+
19
+ - `enableColumnDragging` - type `boolean` - Enable or disable column dragging for this column.
20
+ - `enableColumnOrdering` - type `boolean`
21
+
22
+ ### Relevant State
23
+
24
+ Relevant state options (get_mrt_api has full details):
25
+
26
+ - `columnOrder` - type `Array<string>` - default `[]` - an array of strings representing the current order of the table columns
27
+ - `draggingColumn` - type `MRT_Column | null` - a variable representing the currently dragged column
28
+ - `hoveredColumn` - type `MRT_Column | null`
29
+
30
+ ### Change the Default Column Order
31
+
32
+ By Default, Material React Table will order the columns in the order they are defined in the `columns` table option. And Display Columns such as Actions, Selection, Expansion, etc., get added to either the beginning or the end of the table. You can customize all of this by defining your own `columnOrder` state and passing it either to the `initialState` or `state` table options.
33
+
34
+ The `columnOrder` state is an array of string column ids, that come from the ids or accessorKeys that you defined in your column definitions.
35
+
36
+ If you are enabling features that generate built-in MRT display columns such as `enableRowSelection`, `enableRowNumbers`, `enableRowActions`, etc., you should include those column ids in your `columnOrder` state at the index you want them to appear in the table. If you do not include them, MRT should automatically insert them at either the beginning or the end of the table just fine, but it might not be in the order you want.
37
+
38
+ See the [Display Columns Guide](/docs/guides/display-columns) for more information on what `"mrt-row-\*"` column ids are available.
39
+
40
+ ```jsx
41
+ const table = useMaterialReactTable({
42
+ data,
43
+ columns,
44
+ enableRowSelection: true,
45
+ initialState: {
46
+ columnOrder: [
47
+ 'name',
48
+ 'email',
49
+ 'phone',
50
+ 'city',
51
+ 'country',
52
+ 'mrt-row-select', //move the built-in selection column to the end of the table
53
+ ],
54
+ },
55
+ });
56
+
57
+ return <MaterialReactTable table={table} />;
58
+ ```
59
+
60
+ > **Note:** If the number of `columns` and the length of the `columnOrder` state do not match, MRT will automatically re-generate the `columnOrder` state internally as of v2.10.0.
61
+
62
+ ### Manage Column Order State
63
+
64
+ If you need easier access to the `columnOrder` state, you can store the column order in your own state management, and then pass it back into the MRT `state` table option and sync back up internal mutations with the `onColumnOrderChange` callback.
65
+
66
+ You should also should initialize the `columnOrder` state yourself for the best results. Though, as of v2.10.0, if you do not initialize the `columnOrder` state, as Material React Table will generate a default column order for you based on the order of the columns passed in the `columns` option, so you only need to properly initialize the column order state if there is a problem with the default order.
67
+
68
+ ```jsx
69
+ const columns = [
70
+ //...
71
+ ];
72
+
73
+ //easy shortcut to initialize the columnOrder state as array of column ids
74
+ const [columnOrder, setColumnOrder] = useState(
75
+ ['mrt-row-select', ...columns.map((c) => c.accessorKey)], //array of column ids (Initializing is optional as of v2.10.0)
76
+ );
77
+
78
+ const table = useMaterialReactTable({
79
+ data,
80
+ columns,
81
+ enableRowSelection: true,
82
+ state: {
83
+ columnOrder,
84
+ },
85
+ onColumnOrderChange: setColumnOrder,
86
+ });
87
+
88
+ return <MaterialReactTable table={table} />;
89
+ ```
90
+
91
+ ### Enable Column Ordering with Drag and Drop
92
+
93
+ Material React Table has a built-in drag and drop feature to reorder columns. This feature is enabled by passing the `enableColumnOrdering` table option.
94
+
95
+ The ability for a column to have a drag and drop handle can be specified by setting the `enableColumnOrdering` option on the column.
96
+
97
+ > Live example: `enable-column-ordering` (call get_mrt_example with that id).
98
+
99
+ View Extra Storybook **[Examples](https://www.material-react-table.dev/?path=/story/features-column-ordering-examples)**
@@ -0,0 +1,72 @@
1
+ ## Column Pinning Feature Guide
2
+
3
+ Column pinning is a cool feature that lets users pin (freeze) columns to the left or right of the table. Pinned columns will not scroll horizontally with the rest of the columns so that they always stay visible to the user.
4
+
5
+ ### Relevant Table Options
6
+
7
+ Relevant table options (get_mrt_api has full details):
8
+
9
+ - `enableColumnPinning` - type `boolean`
10
+ - `onColumnPinningChange` - type `OnChangeFn<ColumnPinningState>` - If provided, this function will be called with an updaterFn when state.columnPinning changes. This overrides the default internal state management, so you will need to persist the state change either fully or partially outside of the table.
11
+
12
+ ### Relevant Column Options
13
+
14
+ Relevant column options (get_mrt_api has full details):
15
+
16
+ - `enablePinning` - type `boolean`
17
+
18
+ ### Relevant State
19
+
20
+ Relevant state options (get_mrt_api has full details):
21
+
22
+ - `columnPinning` - type `{ left: Array<string>, right: Array<string> }` - default `{ left: [], right: [] }` - an object with left and right properties, each of which is an array of strings representing the columns that are pinned to the left or right side of the table
23
+
24
+ ### Enable Column Pinning
25
+
26
+ Column pinning can simply be enabled by setting the `enableColumnPinning` table option to `true`.
27
+
28
+ ```jsx
29
+ const table = useMaterialReactTable({
30
+ data,
31
+ columns,
32
+ enableColumnPinning: true,
33
+ });
34
+
35
+ return <MaterialReactTable table={table} />;
36
+ ```
37
+
38
+ ### Pin (Freeze) Columns By Default
39
+
40
+ Columns can start out pinned in your table by setting the `columnPinning` states in `initialState` or `state`.
41
+
42
+ ```jsx
43
+ const table = useMaterialReactTable({
44
+ data,
45
+ columns,
46
+ enableColumnPinning: true,
47
+ initialState: { columnPinning: { start: ['email'] } }, //pin email column to the start by default
48
+ });
49
+
50
+ return <MaterialReactTable table={table} />;
51
+ ```
52
+
53
+ ### Apply Absolute Column Widths
54
+
55
+ You might consider using the `layoutMode: 'grid-no-grow'` table option to give all columns an exact width if you don't want the columns collapsing a little while scrolling. Some people like this subtle behavior, but others do not.
56
+
57
+ ```jsx
58
+ const table = useMaterialReactTable({
59
+ data,
60
+ columns,
61
+ enableColumnPinning: true,
62
+ layoutMode: 'grid-no-grow',
63
+ });
64
+
65
+ return <MaterialReactTable table={table} />;
66
+ ```
67
+
68
+ #### Column Pinning Example
69
+
70
+ > Live example: `enable-column-pinning` (call get_mrt_example with that id).
71
+
72
+ View Extra Storybook **[Examples](https://www.material-react-table.dev/?path=/story/features-column-pinning-examples)**
@@ -0,0 +1,157 @@
1
+ ## Column Resizing Feature Guide
2
+
3
+ Material React Table has a built-in column resizing draggable handle feature.
4
+
5
+ > The Column Size features was recently split into its own [Guide](/docs/guides/column-size). View that guide as a prerequisite to this one.
6
+
7
+ ### Relevant Table Options
8
+
9
+ Relevant table options (get_mrt_api has full details):
10
+
11
+ - `columnResizeDirection` - type `'ltr' | 'rtl'` - default `muiTheme.direction || 'ltr'` - Determines the direction of column resizing. ltr = left to right, rtl = right to left.
12
+ - `columnResizeMode` - type `'onEnd' | 'onChange'` - default `'onChange'` - Determines when the columnSizing state is updated. onChange updates the state when the user is dragging the resize handle. onEnd updates the state when the user releases the resize handle.
13
+ - `defaultColumn` - type `Partial<MRT_ColumnDef<TData>>` - Default column options to use for all column defs supplied to the table. This is useful for providing default cell/header/footer renderers, sorting/filtering/grouping options, etc.
14
+ - `defaultDisplayColumn` - type `Partial<MRT_DisplayColumnDef<TData>>` - Default column options to use for all display column defs supplied to the table. This is useful for providing default cell/header/footer renderers, or turning on or off certain features for all display columns.
15
+ - `displayColumnDefOptions` - type `{ [key: string]: MRT_DisplayColumnDef<TData> }` - Customize and override the column definition options for the built-in display columns. (Select, Expand, Row Actions, etc.)
16
+ - `enableColumnResizing` - type `boolean`
17
+ - `layoutMode` - type `'semantic' | 'grid' | 'grid-no-grow'` - default `'semantic' //(changes based on other enabled features)`
18
+ - `onColumnResizingChange` - type `OnChangeFn<MRT_ColumnResizingState>` - This optional function will be called when the columnResizing state changes. If you provide this function, you will be responsible for maintaining its state yourself. You can pass this state back to the table via the state.columnSizingInfo table option.
19
+ - `onColumnSizingChange` - type `OnChangeFn<ColumnSizingState>` - This optional function will be called when the columnSizing state changes. If you provide this function, you will be responsible for maintaining its state yourself. You can pass this state back to the table via the state.columnSizing table option.
20
+
21
+ ### Relevant Column Options
22
+
23
+ Relevant column options (get_mrt_api has full details):
24
+
25
+ - `enableResizing` - type `boolean`
26
+ - `grow` - type `boolean | number` - If `layoutMode` is `'grid'` or `'grid-no-grow'`, you can specify the flex grow value for individual columns to still grow and take up remaining space, or set to `false`/0 to not grow.
27
+ - `maxSize` - type `number` - default `1000`
28
+ - `minSize` - type `number` - default `40`
29
+ - `size` - type `number` - default `180`
30
+
31
+ ### Relevant State
32
+
33
+ Relevant state options (get_mrt_api has full details):
34
+
35
+ - `columnResizing` - type `See TanStack Docs` - default `{}` - an object containing information about column sizing
36
+ - `columnSizing` - type `Record<string, number>` - default `{}` - an object mapping column IDs to their current width in pixels
37
+
38
+ ### Initial Column Sizes
39
+
40
+ Column sizes will behave differently depending on which `layoutMode` you have set.
41
+
42
+ See the [Column Size Guide](/docs/guides/column-size) for more information on layout modes and how to set initial column sizes properly for you use case.
43
+
44
+ ### Enable Column Resizing Feature
45
+
46
+ `enableColumnResizing` is the boolean table option that enables the column resizing feature.
47
+
48
+ ```jsx
49
+ const table = useMaterialReactTable({
50
+ columns,
51
+ data,
52
+ enableColumnResizing: true,
53
+ });
54
+
55
+ return <MaterialReactTable table={table} />;
56
+ ```
57
+
58
+ You can disable specific columns from being resizable by setting the `enableResizing` column option to false in their respective column definition.
59
+
60
+ ### Column Resize Mode
61
+
62
+ The default `columnResizeMode` is `onChange` (in MRT versions v1.7+), which means that the column resizing will occur immediately as the user drags the column resize handle. If you are running into performance issues because of many other enabled features, you might want to set the `columnResizeMode` to `onEnd` instead. This will make the column resizing only occur after the user has finished dragging the column resize handle and released their mouse.
63
+
64
+ ```jsx
65
+ const table = useMaterialReactTable({
66
+ columns,
67
+ data,
68
+ enableColumnResizing: true,
69
+ columnResizeMode: 'onEnd', //instead of the default "onChange" mode
70
+ });
71
+ ```
72
+
73
+ > Live example: `enable-column-resizing` (call get_mrt_example with that id).
74
+
75
+ ### Column Growing
76
+
77
+ > MRT V3 has a new "opposite" behavior in regards to column sizes when column resizing is enabled compared to MRT V3
78
+
79
+ When column resizing is enabled, by default, a layoutMode of `"grid-no-grow"` will be applied internally. This means that columns will have an absolute size and they will NOT grow to fill in the remaining space of the table. You can let columns grow to fill in the remaining space by changing the `layoutMode` back to `"grid"` or `"semantic"`.
80
+
81
+ ```jsx
82
+ const table = useMaterialReactTable({
83
+ columns,
84
+ data,
85
+ enableColumnResizing: true,
86
+ layoutMode: 'grid', //instead of the default "grid-no-grow" when column resizing is enabled
87
+ });
88
+ ```
89
+
90
+ Alternatively, if you only want certain columns to grow to fill the remaining space, you can set the `grow` column option to `true` in their respective column definitions.
91
+
92
+ ```jsx
93
+ const columns = [
94
+ //...
95
+ {
96
+ accessorKey: 'address',
97
+ header: 'Address',
98
+ size: 250,
99
+ grow: true, //allow this column to grow to fill the remaining space
100
+ },
101
+ ];
102
+ ```
103
+
104
+ This is discussed in more detail in the [Column Size Guide](/docs/guides/column-size#column-grow).
105
+
106
+ ### Column Resize Direction
107
+
108
+ > New in V3.1
109
+
110
+ If you are displaying your table in a RTL (right-to-left) language, you can set the `columnResizeDirection` table option to `"rtl"` to make the column resize handle appear on the left side of the column instead of the right side. This may behave differently depending on which Emotion or MUI theme settings you have enabled.
111
+
112
+ If you have already set the proper `theme.direction` setting in your MUI theme, then this option will already have been set automatically for you, but you can still override it using the `columnResizeDirection` table option.
113
+
114
+ ```jsx
115
+ const table = useMaterialReactTable({
116
+ columns,
117
+ data,
118
+ enableColumnResizing: true,
119
+ columnResizeDirection: 'rtl', //instead of the default "ltr" direction
120
+ });
121
+
122
+ return (
123
+ <div style={{ direction: 'rtl' }}>
124
+ {' '}
125
+ {/* app-wide style? */}
126
+ <MaterialReactTable table={table} />
127
+ </div>
128
+ );
129
+ ```
130
+
131
+ > Live example: `localization-i18n-fa` (call get_mrt_example with that id).
132
+
133
+ ### Enable Resizing on Built-in Display Columns
134
+
135
+ As discussed further in the [Display Columns Guide](/docs/guides/display-columns), you can customize the options of the built-in columns that get generated under the hood by MRT by enabling certain features.
136
+
137
+ Here, we can enable column resizing on the built-in row numbers column by setting the `enableResizing` column option to true in the `displayColumnDefOptions` table option.
138
+
139
+ ```jsx
140
+ const table = useMaterialReactTable({
141
+ columns,
142
+ data,
143
+ displayColumnDefOptions: {
144
+ 'mrt-row-numbers': {
145
+ enableResizing: true, //allow the row numbers column to be resized
146
+ size: 40,
147
+ grow: false, //new in v2.8 - do not fill remaining space using this column
148
+ },
149
+ },
150
+ enableRowNumbers: true,
151
+ layoutMode: 'grid', // `grow` only works in the grid* layout modes
152
+ });
153
+
154
+ return <MaterialReactTable table={table} />;
155
+ ```
156
+
157
+ View Extra Storybook **[Examples](https://www.material-react-table.dev/?path=/story/features-column-resizing-examples)**
@@ -0,0 +1,162 @@
1
+ ## Column Size Feature Guide
2
+
3
+ Material React Table lets you easily change the default widths (sizes) of columns.
4
+
5
+ ### Relevant Table Options
6
+
7
+ Relevant table options (get_mrt_api has full details):
8
+
9
+ - `defaultColumn` - type `Partial<MRT_ColumnDef<TData>>` - Default column options to use for all column defs supplied to the table. This is useful for providing default cell/header/footer renderers, sorting/filtering/grouping options, etc.
10
+ - `defaultDisplayColumn` - type `Partial<MRT_DisplayColumnDef<TData>>` - Default column options to use for all display column defs supplied to the table. This is useful for providing default cell/header/footer renderers, or turning on or off certain features for all display columns.
11
+ - `displayColumnDefOptions` - type `{ [key: string]: MRT_DisplayColumnDef<TData> }` - Customize and override the column definition options for the built-in display columns. (Select, Expand, Row Actions, etc.)
12
+ - `layoutMode` - type `'semantic' | 'grid' | 'grid-no-grow'` - default `'semantic' //(changes based on other enabled features)`
13
+
14
+ ### Relevant Column Options
15
+
16
+ Relevant column options (get_mrt_api has full details):
17
+
18
+ - `grow` - type `boolean | number` - If `layoutMode` is `'grid'` or `'grid-no-grow'`, you can specify the flex grow value for individual columns to still grow and take up remaining space, or set to `false`/0 to not grow.
19
+ - `maxSize` - type `number` - default `1000`
20
+ - `minSize` - type `number` - default `40`
21
+ - `size` - type `number` - default `180`
22
+
23
+ ### Relevant State
24
+
25
+ Relevant state options (get_mrt_api has full details):
26
+
27
+ - `columnSizing` - type `Record<string, number>` - default `{}` - an object mapping column IDs to their current width in pixels
28
+
29
+ ### Layout Modes
30
+
31
+ Material React Table has 3 layout modes that affect how columns styles are applied internally. Depending on which features you enable, the `layoutMode` table option will automatically change to the appropriate value, though you can override it with your own value if you want.
32
+
33
+ 1. `"semantic"` (default with default features) - uses default css styles that come with `<table>`, `<tr>`, `<td>`, etc. elements.
34
+ 2. `"grid"` (default when virtualization is enabled) - uses CSS Grid and Flexbox styles instead of default styles.
35
+ 3. `"grid-no-grow"` (default when column resizing is enabled) - uses CSS Grid and Flexbox styles, but also sets `flex-grow: 0` on all columns and adds an empty "spacer" column to the end of the table to fill the potential remaining space.
36
+
37
+ If you want your columns to have an absolute width, you can use the `"grid-no-grow"` layout mode and set the `size` option on each column.
38
+
39
+ ### Column Size
40
+
41
+ You can change the width of any column by setting its `size` option on the column definition. There are `minSize` and `maxSize` column options available to enforce limits during resizing events.
42
+
43
+ The `size`, `minSize`, and `maxSize` do not take in any CSS width unit. They are only numbers that represent the width of the column in pixels.
44
+
45
+ ```jsx
46
+ const columns = [
47
+ {
48
+ accessorKey: 'id',
49
+ header: 'ID',
50
+ grow: false, //don't allow this column to grow to fill in remaining space - new in v2.8
51
+ size: 50, //small column
52
+ },
53
+ {
54
+ accessorKey: 'username',
55
+ header: 'Username',
56
+ minSize: 100, //min size enforced during resizing
57
+ maxSize: 400, //max size enforced during resizing
58
+ size: 180, //medium column
59
+ },
60
+ {
61
+ accessorKey: 'email',
62
+ header: 'Email',
63
+ grow: true, //allow this column to grow to fill in remaining space - new in v2.8
64
+ size: 300, //large column
65
+ },
66
+ ];
67
+ ```
68
+
69
+ ### Column Grow
70
+
71
+ > New in v2.8 - You can now set a `grow` column option if using layoutMode `"grid-no-grow"` or `"grid"`
72
+
73
+ You can also set `grow` properties on the column definitions when using layoutMode `"grid-no-grow"` or `"grid"`.
74
+
75
+ If the layout mode of your table is `"grid"` and you set `grow: false` on a column, that column will have a fixed size and will not grow to fill in the remaining space of the table.
76
+
77
+ If the layout mode of your table is `"grid-no-grow"` and you set `grow: true` on a column, that column will grow to fill in the remaining space of the table.
78
+
79
+ If the layout mode of your table is `"grid-no-grow"` and you set `grow: 1` on one column, and `grow: 2` on another column, the first column will grow to fill in 1/3 of the remaining space of the table, and the second column will grow to fill in 2/3 of the remaining space of the table.
80
+
81
+ If the layout mode of your table is `"semantic"`, the `grow` column option will have no effect, but columns will size themselves to fit their own content better than the other layout modes.
82
+
83
+ ### But I Want My Columns to Have a Percentage Width
84
+
85
+ Material React Table is not designed to use percentage column widths well by default. This is because having horizontal scrollbars on tables is both a very common use case, and usually the best way to ensure that the actual content of the cells in each column is visible and not cutoff or wrapped excessively.
86
+
87
+ If you disagree with that, that's fair, and you're not out of luck. Material React Table exposes all mui props, so if you really want to, you can add whatever CSS you want to achieve your own custom column widths behavior. This is not recommended by the maintainer, but some developers have found it useful to set all column sizes and minSizes to a very small number like `1`, `1.5`, `2`, ect., and then use either `layoutMode: "semantic"` or `layoutMode: "grid"`. This makes the columns act more like they are using percentage widths, up until a certain point. If you really need to never have a horizontal scrollbar, you can edit the `muiTableContainerProps.sx` styles to set `overflowX: "hidden"`. Be very careful with this though, as this could cause your table to be unusable on smaller screens.
88
+
89
+ If the above still does not get you to where you need to be, `muiTableHeadCellProps.sx`, `muiTableBodyCellProps.sx`, and `muiTableFooterCellProps.sx` and more are all exposed and available to you to override with whatever custom CSS that you need. Just be aware that non of the built-in TanStack Table size APIs will be accurate anymore.
90
+
91
+ #### Side Note: Just Make Your Scrollbars Prettier
92
+
93
+ Making your scrollbars look better (especially on Windows and Linux) can go a long way to not letting a horizontal scrollbar ruin the look of your table.
94
+
95
+ Here's what this docs site uses in its global CSS to make scrollbars to more like the default Mac OS scrollbars for everyone:
96
+
97
+ ```css
98
+ ::-webkit-scrollbar-track {
99
+ background-color: transparent;
100
+ }
101
+
102
+ ::-webkit-scrollbar {
103
+ right: 0;
104
+ width: 12px;
105
+ height: 12px;
106
+ }
107
+
108
+ ::-webkit-scrollbar-thumb {
109
+ background-color: #999;
110
+ border-radius: 8px;
111
+ width: 12px;
112
+ height: 12px;
113
+ }
114
+ ```
115
+
116
+ ### Default Column
117
+
118
+ By default, columns will have the following size properties defined:
119
+
120
+ ```jsx
121
+ defaultColumn = { minSize: 40, maxSize: 1000, size: 180 }; //units are in px
122
+ ```
123
+
124
+ You can modify the default column widths by setting the `defaultColumn` table option on the table.
125
+
126
+ ```jsx
127
+ const table = useMaterialReactTable({
128
+ columns,
129
+ data,
130
+ defaultColumn: {
131
+ minSize: 20, //allow columns to get smaller than default
132
+ maxSize: 9001, //allow columns to get larger than default
133
+ size: 260, //make columns wider by default
134
+ },
135
+ });
136
+ ```
137
+
138
+ ### Change Sizes of Built-in Display Columns
139
+
140
+ As discussed further in the [Display Columns Guide](/docs/guides/display-columns), you can customize the options of the built-in columns that get generated under the hood by MRT by enabling certain features.
141
+
142
+ ```jsx
143
+ const table = useMaterialReactTable({
144
+ columns,
145
+ data,
146
+ displayColumnDefOptions: {
147
+ 'mrt-row-select': {
148
+ size: 50, //adjust the size of the row select column
149
+ grow: false, //new in v2.8 (default is false for this column)
150
+ },
151
+ 'mrt-row-numbers': {
152
+ size: 40,
153
+ grow: true, //new in v2.8 (allow this column to grow to fill in remaining space)
154
+ },
155
+ },
156
+ enableRowNumbers: true,
157
+ });
158
+
159
+ return <MaterialReactTable table={table} />;
160
+ ```
161
+
162
+ View Extra Storybook **[Examples](https://www.material-react-table.dev/?path=/story/styling-custom-column-widths)**