MCPcopy Index your code
hub / github.com/TanStack/table / createHeader

Function createHeader

packages/table-core/src/core/headers.ts:213–263  ·  view source on GitHub ↗
(
  table: Table<TData>,
  column: Column<TData, TValue>,
  options: {
    id?: string
    isPlaceholder?: boolean
    placeholderId?: string
    index: number
    depth: number
  },
)

Source from the content-addressed store, hash-verified

211//
212
213function createHeader<TData extends RowData, TValue>(
214 table: Table<TData>,
215 column: Column<TData, TValue>,
216 options: {
217 id?: string
218 isPlaceholder?: boolean
219 placeholderId?: string
220 index: number
221 depth: number
222 },
223): Header<TData, TValue> {
224 const id = options.id ?? column.id
225
226 let header: CoreHeader<TData, TValue> = {
227 id,
228 column,
229 index: options.index,
230 isPlaceholder: !!options.isPlaceholder,
231 placeholderId: options.placeholderId,
232 depth: options.depth,
233 subHeaders: [],
234 colSpan: 0,
235 rowSpan: 0,
236 headerGroup: null!,
237 getLeafHeaders: (): Header<TData, unknown>[] => {
238 const leafHeaders: Header<TData, unknown>[] = []
239
240 const recurseHeader = (h: CoreHeader<TData, any>) => {
241 if (h.subHeaders && h.subHeaders.length) {
242 h.subHeaders.map(recurseHeader)
243 }
244 leafHeaders.push(h as Header<TData, unknown>)
245 }
246
247 recurseHeader(header)
248
249 return leafHeaders
250 },
251 getContext: () => ({
252 table,
253 header: header as Header<TData, TValue>,
254 column,
255 }),
256 }
257
258 table._features.forEach((feature) => {
259 feature.createHeader?.(header as Header<TData, TValue>, table)
260 })
261
262 return header as Header<TData, TValue>
263}
264
265export const Headers: TableFeature = {
266 createTable: <TData extends RowData>(table: Table<TData>): void => {

Callers 2

createHeaderGroupFunction · 0.85
buildHeaderGroupsFunction · 0.85

Calls 1

recurseHeaderFunction · 0.85

Tested by

no test coverage detected