|
1 | 1 | import React from 'react';
|
2 | 2 | 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'; |
3 | 14 | import * as classes from './users.styles';
|
4 | 15 |
|
| 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 | + |
5 | 57 | export const UsersPod: React.FC = () => {
|
| 58 | + const tableInstance = useReactTable({ |
| 59 | + data, |
| 60 | + columns, |
| 61 | + getCoreRowModel: getCoreRowModel(), |
| 62 | + }); |
| 63 | + |
| 64 | + const { getAllColumns, getRowModel } = tableInstance; |
| 65 | + |
6 | 66 | return (
|
7 | 67 | <div className={classes.root}>
|
8 | 68 | <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> |
9 | 101 | <Link to="/users/$id" params={{ id: '1' }}>
|
10 | 102 | Navegar a detalle de usuario
|
11 | 103 | </Link>
|
|
0 commit comments