Skip to content

Commit

Permalink
chore: fix tableCreator omit
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinVandy committed Jul 13, 2024
1 parent c4910d3 commit ac8a367
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 55 deletions.
93 changes: 40 additions & 53 deletions examples/react/grouping/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,61 +47,48 @@ function App() {
() =>
tableHelper.columnHelper.columns<typeof tableHelper.features, Person>([
{
header: 'Name',
columns: [
{
accessorKey: 'firstName',
header: 'First Name',
cell: (info) => info.getValue(),
/**
* override the value used for row grouping
* (otherwise, defaults to the value derived from accessorKey / accessorFn)
*/
getGroupingValue: (row) => `${row.firstName} ${row.lastName}`,
},
{
accessorFn: (row) => row.lastName,
id: 'lastName',
header: () => <span>Last Name</span>,
cell: (info) => info.getValue(),
},
],
accessorKey: 'firstName',
header: 'First Name',
cell: (info) => info.getValue(),
/**
* override the value used for row grouping
* (otherwise, defaults to the value derived from accessorKey / accessorFn)
*/
getGroupingValue: (row) => `${row.firstName} ${row.lastName}`,
},
{
header: 'Info',
columns: [
{
accessorKey: 'age',
header: () => 'Age',
aggregatedCell: ({ getValue }) =>
Math.round(getValue<number>() * 100) / 100,
aggregationFn: 'median',
},
{
header: 'More Info',
columns: [
{
accessorKey: 'visits',
header: () => <span>Visits</span>,
aggregationFn: 'sum',
// aggregatedCell: ({ getValue }) => getValue().toLocaleString(),
},
{
accessorKey: 'status',
header: 'Status',
},
{
accessorKey: 'progress',
header: 'Profile Progress',
cell: ({ getValue }) =>
Math.round(getValue<number>() * 100) / 100 + '%',
aggregationFn: 'mean',
aggregatedCell: ({ getValue }) =>
Math.round(getValue<number>() * 100) / 100 + '%',
},
],
},
],
accessorFn: (row) => row.lastName,
id: 'lastName',
header: () => <span>Last Name</span>,
cell: (info) => info.getValue(),
},

{
accessorKey: 'age',
header: () => 'Age',
aggregatedCell: ({ getValue }) =>
Math.round(getValue<number>() * 100) / 100,
aggregationFn: 'median',
},

{
accessorKey: 'visits',
header: () => <span>Visits</span>,
aggregationFn: 'sum',
// aggregatedCell: ({ getValue }) => getValue().toLocaleString(),
},
{
accessorKey: 'status',
header: 'Status',
},
{
accessorKey: 'progress',
header: 'Profile Progress',
cell: ({ getValue }) =>
Math.round(getValue<number>() * 100) / 100 + '%',
aggregationFn: 'mean',
aggregatedCell: ({ getValue }) =>
Math.round(getValue<number>() * 100) / 100 + '%',
},
]),
[],
Expand Down
29 changes: 27 additions & 2 deletions packages/react-table/src/tableHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import type {
export type TableHelper<
TFeatures extends TableFeatures,
TData extends RowData,
> = Omit<_TableHelper<TFeatures, TData>, '_createTable'> & {
> = Omit<_TableHelper<TFeatures, TData>, 'tableCreator'> & {
useTable: (
tableOptions: Omit<
TableOptions<TFeatures, TData>,
Expand All @@ -39,7 +39,7 @@ export function createTableHelper<
}
}

//test
// test 1 - TData in table helper

// type Person = {
// firstName: string
Expand All @@ -65,3 +65,28 @@ export function createTableHelper<
// columns,
// data,
// })

// test 2 - TData in column helper

// const tableHelper2 = createTableHelper({
// features: { RowSelection: {} },
// })

// const columns2 = tableHelper2.columnHelper.columns<
// typeof tableHelper2.features,
// Person
// >([
// tableHelper2.columnHelper.accessor('firstName', {
// header: 'First Name',
// }),
// tableHelper2.columnHelper.accessor('lastName', {
// header: 'Last Name',
// }),
// tableHelper2.columnHelper.accessor('age', { header: 'Age' }),
// tableHelper2.columnHelper.display({ header: 'Actions', id: 'actions' }),
// ])

// tableHelper2.useTable({
// columns: columns2,
// data,
// })

0 comments on commit ac8a367

Please sign in to comment.