Skip to content

Commit 4725396

Browse files
committed
chore: move pinned header code out of headers into columnpinning
1 parent 3433c18 commit 4725396

3 files changed

Lines changed: 218 additions & 218 deletions

File tree

packages/table-core/src/core/headers.ts

Lines changed: 0 additions & 217 deletions
Original file line numberDiff line numberDiff line change
@@ -113,99 +113,24 @@ export interface HeadersInstance<TData extends RowData> {
113113
* @link [Guide](https://tanstack.com/table/v8/docs/guide/headers)
114114
*/
115115
getHeaderGroups: () => HeaderGroup<TData>[]
116-
/**
117-
* If pinning, returns the header groups for the left pinned columns.
118-
* @link [API Docs](https://tanstack.com/table/v8/docs/api/core/headers#getleftheadergroups)
119-
* @link [Guide](https://tanstack.com/table/v8/docs/guide/headers)
120-
*/
121-
getLeftHeaderGroups: () => HeaderGroup<TData>[]
122-
/**
123-
* If pinning, returns the header groups for columns that are not pinned.
124-
* @link [API Docs](https://tanstack.com/table/v8/docs/api/core/headers#getcenterheadergroups)
125-
* @link [Guide](https://tanstack.com/table/v8/docs/guide/headers)
126-
*/
127-
getCenterHeaderGroups: () => HeaderGroup<TData>[]
128-
/**
129-
* If pinning, returns the header groups for the right pinned columns.
130-
* @link [API Docs](https://tanstack.com/table/v8/docs/api/core/headers#getrightheadergroups)
131-
* @link [Guide](https://tanstack.com/table/v8/docs/guide/headers)
132-
*/
133-
getRightHeaderGroups: () => HeaderGroup<TData>[]
134-
135116
/**
136117
* Returns the footer groups for the table.
137118
* @link [API Docs](https://tanstack.com/table/v8/docs/api/core/headers#getfootergroups)
138119
* @link [Guide](https://tanstack.com/table/v8/docs/guide/headers)
139120
*/
140121
getFooterGroups: () => HeaderGroup<TData>[]
141-
/**
142-
* If pinning, returns the footer groups for the left pinned columns.
143-
* @link [API Docs](https://tanstack.com/table/v8/docs/api/core/headers#getleftfootergroups)
144-
* @link [Guide](https://tanstack.com/table/v8/docs/guide/headers)
145-
*/
146-
getLeftFooterGroups: () => HeaderGroup<TData>[]
147-
/**
148-
* If pinning, returns the footer groups for columns that are not pinned.
149-
* @link [API Docs](https://tanstack.com/table/v8/docs/api/core/headers#getcenterfootergroups)
150-
* @link [Guide](https://tanstack.com/table/v8/docs/guide/headers)
151-
*/
152-
getCenterFooterGroups: () => HeaderGroup<TData>[]
153-
/**
154-
* If pinning, returns the footer groups for the right pinned columns.
155-
* @link [API Docs](https://tanstack.com/table/v8/docs/api/core/headers#getrightfootergroups)
156-
* @link [Guide](https://tanstack.com/table/v8/docs/guide/headers)
157-
*/
158-
getRightFooterGroups: () => HeaderGroup<TData>[]
159-
160122
/**
161123
* Returns headers for all columns in the table, including parent headers.
162124
* @link [API Docs](https://tanstack.com/table/v8/docs/api/core/headers#getflatheaders)
163125
* @link [Guide](https://tanstack.com/table/v8/docs/guide/headers)
164126
*/
165127
getFlatHeaders: () => Header<TData, unknown>[]
166-
/**
167-
* If pinning, returns headers for all left pinned columns in the table, including parent headers.
168-
* @link [API Docs](https://tanstack.com/table/v8/docs/api/core/headers#getleftflatheaders)
169-
* @link [Guide](https://tanstack.com/table/v8/docs/guide/headers)
170-
*/
171-
getLeftFlatHeaders: () => Header<TData, unknown>[]
172-
/**
173-
* If pinning, returns headers for all columns that are not pinned, including parent headers.
174-
* @link [API Docs](https://tanstack.com/table/v8/docs/api/core/headers#getcenterflatheaders)
175-
* @link [Guide](https://tanstack.com/table/v8/docs/guide/headers)
176-
*/
177-
getCenterFlatHeaders: () => Header<TData, unknown>[]
178-
/**
179-
* If pinning, returns headers for all right pinned columns in the table, including parent headers.
180-
* @link [API Docs](https://tanstack.com/table/v8/docs/api/core/headers#getrightflatheaders)
181-
* @link [Guide](https://tanstack.com/table/v8/docs/guide/headers)
182-
*/
183-
getRightFlatHeaders: () => Header<TData, unknown>[]
184-
185128
/**
186129
* Returns headers for all leaf columns in the table, (not including parent headers).
187130
* @link [API Docs](https://tanstack.com/table/v8/docs/api/core/headers#getleafheaders)
188131
* @link [Guide](https://tanstack.com/table/v8/docs/guide/headers)
189132
*/
190133
getLeafHeaders: () => Header<TData, unknown>[]
191-
/**
192-
* If pinning, returns headers for all left pinned leaf columns in the table, (not including parent headers).
193-
* @link [API Docs](https://tanstack.com/table/v8/docs/api/core/headers#getleftleafheaders)
194-
* @link [Guide](https://tanstack.com/table/v8/docs/guide/headers)
195-
*/
196-
getLeftLeafHeaders: () => Header<TData, unknown>[]
197-
/**
198-
* If pinning, returns headers for all columns that are not pinned, (not including parent headers).
199-
* @link [API Docs](https://tanstack.com/table/v8/docs/api/core/headers#getcenterleafheaders)
200-
* @link [Guide](https://tanstack.com/table/v8/docs/guide/headers)
201-
*/
202-
getCenterLeafHeaders: () => Header<TData, unknown>[]
203-
/**
204-
* If pinning, returns headers for all right pinned leaf columns in the table, (not including parent headers).
205-
* @link [API Docs](https://tanstack.com/table/v8/docs/api/core/headers#getrightleafheaders)
206-
* @link [Guide](https://tanstack.com/table/v8/docs/guide/headers)
207-
*/
208-
getRightLeafHeaders: () => Header<TData, unknown>[]
209134
}
210135

211136
//
@@ -264,8 +189,6 @@ function _createHeader<TData extends RowData, TValue>(
264189

265190
export const Headers: TableFeature = {
266191
_createTable: <TData extends RowData>(table: Table<TData>): void => {
267-
// Header Groups
268-
269192
table.getHeaderGroups = memo(
270193
() => [
271194
table.getAllColumns(),
@@ -299,58 +222,6 @@ export const Headers: TableFeature = {
299222
getMemoOptions(table.options, debug, 'getHeaderGroups')
300223
)
301224

302-
table.getCenterHeaderGroups = memo(
303-
() => [
304-
table.getAllColumns(),
305-
table.getVisibleLeafColumns(),
306-
table.getState().columnPinning.left,
307-
table.getState().columnPinning.right,
308-
],
309-
(allColumns, leafColumns, left, right) => {
310-
leafColumns = leafColumns.filter(
311-
column => !left?.includes(column.id) && !right?.includes(column.id)
312-
)
313-
return buildHeaderGroups(allColumns, leafColumns, table, 'center')
314-
},
315-
getMemoOptions(table.options, debug, 'getCenterHeaderGroups')
316-
)
317-
318-
table.getLeftHeaderGroups = memo(
319-
() => [
320-
table.getAllColumns(),
321-
table.getVisibleLeafColumns(),
322-
table.getState().columnPinning.left,
323-
],
324-
(allColumns, leafColumns, left) => {
325-
const orderedLeafColumns =
326-
left
327-
?.map(columnId => leafColumns.find(d => d.id === columnId)!)
328-
.filter(Boolean) ?? []
329-
330-
return buildHeaderGroups(allColumns, orderedLeafColumns, table, 'left')
331-
},
332-
getMemoOptions(table.options, debug, 'getLeftHeaderGroups')
333-
)
334-
335-
table.getRightHeaderGroups = memo(
336-
() => [
337-
table.getAllColumns(),
338-
table.getVisibleLeafColumns(),
339-
table.getState().columnPinning.right,
340-
],
341-
(allColumns, leafColumns, right) => {
342-
const orderedLeafColumns =
343-
right
344-
?.map(columnId => leafColumns.find(d => d.id === columnId)!)
345-
.filter(Boolean) ?? []
346-
347-
return buildHeaderGroups(allColumns, orderedLeafColumns, table, 'right')
348-
},
349-
getMemoOptions(table.options, debug, 'getRightHeaderGroups')
350-
)
351-
352-
// Footer Groups
353-
354225
table.getFooterGroups = memo(
355226
() => [table.getHeaderGroups()],
356227
headerGroups => {
@@ -359,32 +230,6 @@ export const Headers: TableFeature = {
359230
getMemoOptions(table.options, debug, 'getFooterGroups')
360231
)
361232

362-
table.getLeftFooterGroups = memo(
363-
() => [table.getLeftHeaderGroups()],
364-
headerGroups => {
365-
return [...headerGroups].reverse()
366-
},
367-
getMemoOptions(table.options, debug, 'getLeftFooterGroups')
368-
)
369-
370-
table.getCenterFooterGroups = memo(
371-
() => [table.getCenterHeaderGroups()],
372-
headerGroups => {
373-
return [...headerGroups].reverse()
374-
},
375-
getMemoOptions(table.options, debug, 'getCenterFooterGroups')
376-
)
377-
378-
table.getRightFooterGroups = memo(
379-
() => [table.getRightHeaderGroups()],
380-
headerGroups => {
381-
return [...headerGroups].reverse()
382-
},
383-
getMemoOptions(table.options, debug, 'getRightFooterGroups')
384-
)
385-
386-
// Flat Headers
387-
388233
table.getFlatHeaders = memo(
389234
() => [table.getHeaderGroups()],
390235
headerGroups => {
@@ -397,68 +242,6 @@ export const Headers: TableFeature = {
397242
getMemoOptions(table.options, debug, 'getFlatHeaders')
398243
)
399244

400-
table.getLeftFlatHeaders = memo(
401-
() => [table.getLeftHeaderGroups()],
402-
left => {
403-
return left
404-
.map(headerGroup => {
405-
return headerGroup.headers
406-
})
407-
.flat()
408-
},
409-
getMemoOptions(table.options, debug, 'getLeftFlatHeaders')
410-
)
411-
412-
table.getCenterFlatHeaders = memo(
413-
() => [table.getCenterHeaderGroups()],
414-
left => {
415-
return left
416-
.map(headerGroup => {
417-
return headerGroup.headers
418-
})
419-
.flat()
420-
},
421-
getMemoOptions(table.options, debug, 'getCenterFlatHeaders')
422-
)
423-
424-
table.getRightFlatHeaders = memo(
425-
() => [table.getRightHeaderGroups()],
426-
left => {
427-
return left
428-
.map(headerGroup => {
429-
return headerGroup.headers
430-
})
431-
.flat()
432-
},
433-
getMemoOptions(table.options, debug, 'getRightFlatHeaders')
434-
)
435-
436-
// Leaf Headers
437-
438-
table.getCenterLeafHeaders = memo(
439-
() => [table.getCenterFlatHeaders()],
440-
flatHeaders => {
441-
return flatHeaders.filter(header => !header.subHeaders?.length)
442-
},
443-
getMemoOptions(table.options, debug, 'getCenterLeafHeaders')
444-
)
445-
446-
table.getLeftLeafHeaders = memo(
447-
() => [table.getLeftFlatHeaders()],
448-
flatHeaders => {
449-
return flatHeaders.filter(header => !header.subHeaders?.length)
450-
},
451-
getMemoOptions(table.options, debug, 'getLeftLeafHeaders')
452-
)
453-
454-
table.getRightLeafHeaders = memo(
455-
() => [table.getRightFlatHeaders()],
456-
flatHeaders => {
457-
return flatHeaders.filter(header => !header.subHeaders?.length)
458-
},
459-
getMemoOptions(table.options, debug, 'getRightLeafHeaders')
460-
)
461-
462245
table.getLeafHeaders = memo(
463246
() => [
464247
table.getLeftHeaderGroups(),

0 commit comments

Comments
 (0)