Skip to content

Commit b419811

Browse files
ManoloManolo
Manolo
authored and
Manolo
committed
add tanstack table
1 parent 5d48781 commit b419811

File tree

4 files changed

+137
-0
lines changed

4 files changed

+137
-0
lines changed

package-lock.json

Lines changed: 32 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"@mui/icons-material": "^6.1.7",
2727
"@mui/material": "^6.1.7",
2828
"@tanstack/react-router": "^1.82.1",
29+
"@tanstack/react-table": "^8.20.5",
2930
"react": "^18.3.1",
3031
"react-dom": "^18.3.1"
3132
},

src/modules/users/list/users.pod.tsx

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,103 @@
11
import React from 'react';
22
import { Link } from '@tanstack/react-router';
3+
import { ColumnDef, useReactTable, getCoreRowModel } from '@tanstack/react-table';
4+
import {
5+
Table,
6+
TableBody,
7+
TableCell,
8+
TableContainer,
9+
TableHead,
10+
TableRow,
11+
TablePagination,
12+
Paper,
13+
} from '@mui/material';
314
import * as classes from './users.styles';
415

16+
interface Data {
17+
id: number;
18+
name: string;
19+
age: number;
20+
city: string;
21+
}
22+
23+
const data: Data[] = [
24+
{ id: 1, name: 'Alice', age: 25, city: 'New York' },
25+
{ id: 2, name: 'Bob', age: 30, city: 'San Francisco' },
26+
{ id: 3, name: 'Charlie', age: 35, city: 'Chicago' },
27+
{ id: 4, name: 'Diana', age: 28, city: 'Los Angeles' },
28+
{ id: 5, name: 'Eve', age: 22, city: 'Miami' },
29+
{ id: 6, name: 'Frank', age: 27, city: 'Seattle' },
30+
{ id: 7, name: 'Grace', age: 32, city: 'Boston' },
31+
{ id: 8, name: 'Hank', age: 29, city: 'Denver' },
32+
{ id: 9, name: 'Ivy', age: 24, city: 'Portland' },
33+
{ id: 10, name: 'Jack', age: 31, city: 'Austin' },
34+
{ id: 11, name: 'Kate', age: 26, city: 'Houston' },
35+
{ id: 12, name: 'Lance', age: 33, city: 'Atlanta' },
36+
];
37+
38+
const columns: ColumnDef<Data>[] = [
39+
{
40+
accessorKey: 'id',
41+
header: 'ID',
42+
},
43+
{
44+
accessorKey: 'name',
45+
header: 'Name',
46+
},
47+
{
48+
accessorKey: 'age',
49+
header: 'Age',
50+
},
51+
{
52+
accessorKey: 'city',
53+
header: 'City',
54+
},
55+
];
56+
557
export const UsersPod: React.FC = () => {
58+
const tableInstance = useReactTable({
59+
data,
60+
columns,
61+
getCoreRowModel: getCoreRowModel(),
62+
});
63+
64+
const { getAllColumns, getRowModel } = tableInstance;
65+
666
return (
767
<div className={classes.root}>
868
<h1>Soy la página de listado de usuarios</h1>
69+
<TableContainer component={Paper}>
70+
<Table sx={{ minWidth: 1200 }}>
71+
<TableHead>
72+
<TableRow>
73+
{getAllColumns().map(column => (
74+
<TableCell key={column.id} className={classes.head}>
75+
{column.id}
76+
</TableCell>
77+
))}
78+
</TableRow>
79+
</TableHead>
80+
<TableBody>
81+
{getRowModel().rows.map(row => (
82+
<TableRow key={row.id} className={classes.row}>
83+
<TableCell>{row.original.id}</TableCell>
84+
<TableCell>{row.original.name}</TableCell>
85+
<TableCell>{row.original.age}</TableCell>
86+
<TableCell>{row.original.city}</TableCell>
87+
</TableRow>
88+
))}
89+
</TableBody>
90+
</Table>
91+
<TablePagination
92+
rowsPerPageOptions={[5, 10, 25]}
93+
component="div"
94+
count={data.length}
95+
rowsPerPage={5}
96+
page={0}
97+
onPageChange={() => {}}
98+
onRowsPerPageChange={() => {}}
99+
/>
100+
</TableContainer>
9101
<Link to="/users/$id" params={{ id: '1' }}>
10102
Navegar a detalle de usuario
11103
</Link>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,20 @@
11
import { css } from '@emotion/css';
2+
import { theme } from '#core/theme/theme.ts';
23

34
export const root = css`
45
display: flex;
56
flex-direction: column;
67
gap: 30px;
78
align-items: center;
89
`;
10+
11+
export const head = css`
12+
background-color: ${theme.palette.common.black};
13+
color: ${theme.palette.common.white};
14+
`;
15+
16+
export const row = css`
17+
&:nth-of-type(odd) {
18+
background-color: ${theme.palette.action.hover};
19+
}
20+
`;

0 commit comments

Comments
 (0)