1- import {
1+ /* eslint-disable max-lines */
2+ import {
23 getCoreRowModel ,
34 getExpandedRowModel ,
45 getFilteredRowModel ,
@@ -38,6 +39,7 @@ const useReactDataTable = <TData, TFilter extends FilterModel = Record<string, n
3839 onSortingChange,
3940 onRowSelectionChange,
4041 onExpandedChange,
42+ onColumnPinningChange,
4143 reactTableOptions,
4244 } = props ;
4345
@@ -47,13 +49,15 @@ const useReactDataTable = <TData, TFilter extends FilterModel = Record<string, n
4749 pagination : paginationInitial ,
4850 rowSelection : rowSelectionInitial ,
4951 expanded : expandedInitial ,
52+ columnPinning : columnPinningInitial ,
5053 } = initialState ?? { } ;
5154 const {
5255 columnFilters : columnFiltersExternal ,
5356 pagination : paginationExternal ,
5457 sorting : sortingExternal ,
5558 rowSelection : rowSelectionExternal ,
5659 expanded : expandedExternal ,
60+ columnPinning : columnPinningExternal ,
5761 } = state ?? { } ;
5862
5963 const {
@@ -62,29 +66,34 @@ const useReactDataTable = <TData, TFilter extends FilterModel = Record<string, n
6266 sorting : sortingInternal ,
6367 rowSelection : rowSelectionInteral ,
6468 expanded : expandedInternal ,
69+ columnPinning : columnPinningInternal ,
6570 setColumnFilters : setColumnFiltersInternal ,
6671 setPagination : setPaginationInternal ,
6772 setSorting : setSortingInternal ,
6873 setRowSelection : setRowSelectionInternal ,
6974 setExpanded : setExpandedInternal ,
75+ setColumnPinning : setColumnPinningInternal ,
7076 } = useReactDataTableState < TData , TFilter > ( {
7177 initialColumnFilters : columnFiltersInitial as TFilter ,
7278 initialPagination : paginationInitial ,
7379 initialSorting : sortingInitial ,
7480 rowSelection : rowSelectionInitial ,
7581 expanded : expandedInitial ,
82+ columnPinning : columnPinningInitial ,
7683 } as unknown as OptionalNullable < useReactDataTableStateProps < TData , TFilter > > ) ;
7784
7885 const effectiveColumnFilters = columnFiltersExternal ?? columnFiltersInternal ;
7986 const effectivePagination = paginationExternal ?? paginationInternal ;
8087 const effectiveSorting = sortingExternal ?? sortingInternal ;
8188 const effectiveRowSelection = rowSelectionExternal ?? rowSelectionInteral ;
8289 const effectiveExpanded = expandedExternal ?? expandedInternal ;
90+ const effectiveColumnPinning = columnPinningExternal ?? columnPinningInternal ;
8391 const effectiveOnColumnFiltersChange = onColumnFiltersChange ?? setColumnFiltersInternal ;
8492 const effectiveOnPaginationChange = onPaginationChange ?? setPaginationInternal ;
8593 const effectiveOnSortingChange = onSortingChange ?? setSortingInternal ;
8694 const effectiveOnRowSelectionChange = onRowSelectionChange ?? setRowSelectionInternal ;
8795 const effectiveOnExpandedChange = onExpandedChange ?? setExpandedInternal ;
96+ const effectiveOnColumnPinningChange = onColumnPinningChange ?? setColumnPinningInternal ;
8897
8998 // If we active the manual filtering, we have to unset the filter function, else it still does automatic filtering
9099 if ( manualFiltering ) columns . forEach ( ( x ) => ( x . filterFn = undefined ) ) ;
@@ -124,20 +133,27 @@ const useReactDataTable = <TData, TFilter extends FilterModel = Record<string, n
124133 const newExpanded = typeof expandedOrUpdaterFn !== "function" ? expandedOrUpdaterFn : expandedOrUpdaterFn ( effectiveExpanded ) ;
125134 return effectiveOnExpandedChange ( newExpanded ) ;
126135 } ,
136+ onColumnPinningChange : ( columnPinningOrUpdaterFn ) => {
137+ const newColumnPinning =
138+ typeof columnPinningOrUpdaterFn !== "function" ? columnPinningOrUpdaterFn : columnPinningOrUpdaterFn ( effectiveColumnPinning ) ;
139+ return effectiveOnColumnPinningChange ( newColumnPinning ) ;
140+ } ,
127141
128142 state : {
129143 columnFilters,
130144 pagination : effectivePagination ,
131145 sorting,
132146 rowSelection : effectiveRowSelection ,
133147 expanded : effectiveExpanded ,
148+ columnPinning : effectiveColumnPinning ,
134149 } ,
135150
136151 initialState : {
137152 columnFilters : getColumnFilterFromModel ( columnFiltersInitial ?? columnFiltersExternal ?? { } ) ,
138153 pagination : paginationInitial ?? paginationExternal ,
139154 sorting : getSortingStateFromModel ( sortingInitial ?? sortingExternal ) ,
140155 expanded : expandedInitial ?? expandedExternal ,
156+ columnPinning : columnPinningInitial ?? columnPinningExternal ,
141157 } ,
142158
143159 getCoreRowModel : getCoreRowModel ( ) ,
@@ -173,11 +189,13 @@ const useReactDataTable = <TData, TFilter extends FilterModel = Record<string, n
173189 sorting : effectiveSorting ,
174190 rowSelection : effectiveRowSelection ,
175191 expanded : effectiveExpanded ,
192+ columnPinning : effectiveColumnPinning ,
176193 setColumnFilters : effectiveOnColumnFiltersChange ,
177194 setPagination : effectiveOnPaginationChange ,
178195 setSorting : effectiveOnSortingChange ,
179196 setRowSelection : effectiveOnRowSelectionChange ,
180197 setExpanded : effectiveOnExpandedChange ,
198+ setColumnPinning : effectiveOnColumnPinningChange ,
181199 } ;
182200} ;
183201
0 commit comments