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

Function createRow

packages/table-core/src/core/row.ts:95–201  ·  view source on GitHub ↗
(
  table: Table<TData>,
  id: string,
  original: TData,
  rowIndex: number,
  depth: number,
  subRows?: Row<TData>[],
  parentId?: string,
)

Source from the content-addressed store, hash-verified

93}
94
95export const createRow = <TData extends RowData>(
96 table: Table<TData>,
97 id: string,
98 original: TData,
99 rowIndex: number,
100 depth: number,
101 subRows?: Row<TData>[],
102 parentId?: string,
103): Row<TData> => {
104 let row: CoreRow<TData> = {
105 id,
106 index: rowIndex,
107 original,
108 depth,
109 parentId,
110 _valuesCache: {},
111 _uniqueValuesCache: {},
112 getValue: (columnId) => {
113 if (row._valuesCache.hasOwnProperty(columnId)) {
114 return row._valuesCache[columnId]
115 }
116
117 const column = table.getColumn(columnId)
118
119 if (!column?.accessorFn) {
120 return undefined
121 }
122
123 row._valuesCache[columnId] = column.accessorFn(
124 row.original as TData,
125 rowIndex,
126 )
127
128 return row._valuesCache[columnId] as any
129 },
130 getUniqueValues: (columnId) => {
131 if (row._uniqueValuesCache.hasOwnProperty(columnId)) {
132 return row._uniqueValuesCache[columnId]
133 }
134
135 const column = table.getColumn(columnId)
136
137 if (!column?.accessorFn) {
138 return undefined
139 }
140
141 if (!column.columnDef.getUniqueValues) {
142 row._uniqueValuesCache[columnId] = [row.getValue(columnId)]
143 return row._uniqueValuesCache[columnId]
144 }
145
146 row._uniqueValuesCache[columnId] = column.columnDef.getUniqueValues(
147 row.original as TData,
148 rowIndex,
149 )
150
151 return row._uniqueValuesCache[columnId] as any
152 },

Callers 3

recurseFilterRowsFunction · 0.90
groupUpRecursivelyFunction · 0.90
accessRowsFunction · 0.90

Calls 4

flattenByFunction · 0.90
memoFunction · 0.90
createCellFunction · 0.90
getMemoOptionsFunction · 0.90

Tested by

no test coverage detected