Table (tabla)
Las tablas muestran conjuntos de datos. Pueden ser totalmente personalizadas.
Las tablas muestran información de una forma fácil de analizar, revelando así patrones e ideas a los usuarios. Se pueden integrar en contenido principal, tal como tarjetas.
Las tablas pueden incluir:
- Un elemento visual correspondiente
- Navegación
- Herramientas para consultar y manipular los datos
Cuando se incluyen herramientas, se deberían poner directamente arriba o debajo de la tabla.
Estructura
Una tabla de datos contiene una cabecera en la parte superior con los nombres de las columnas, seguida por las filas de datos.
Un checkbox debe acompañar a cada fila por si el usuario necesita seleccionar o manipular datos.
Para facilitar la accesibilidad, la primera columna es un elemento <th>
, con un scope
de "row"
. Esto permite a los lectores de pantalla identificar el valor de una celda por el nombre de su fila y columna.
Tabla Sencilla
Un ejemplo sencillo sin florituras.
Dessert (100g serving) | Calories | Fat (g) | Carbs (g) | Protein (g) |
---|---|---|---|---|
Frozen yoghurt | 159 | 6 | 24 | 4 |
Ice cream sandwich | 237 | 9 | 37 | 4.3 |
Eclair | 262 | 16 | 24 | 6 |
Cupcake | 305 | 3.7 | 67 | 4.3 |
Gingerbread | 356 | 16 | 49 | 3.9 |
Dessert (100g serving) | Calories | Fat (g) | Carbs (g) | Protein (g) |
---|---|---|---|---|
Frozen yoghurt | 159 | 6 | 24 | 4 |
Ice cream sandwich | 237 | 9 | 37 | 4.3 |
Eclair | 262 | 16 | 24 | 6 |
Cupcake | 305 | 3.7 | 67 | 4.3 |
Gingerbread | 356 | 16 | 49 | 3.9 |
Ordenando & Seleccionando
Este ejemplo demuestra el uso del Checkbox
y las filas cliqueables para seleccionar, con una Toolbar
personalizado. Utiliza el componente TableSortLabel
para ayudar a dar estilo a las cabeceras de las columnas.
La Tabla tiene un ancho fijo para demostrar el desplazamiento horizontal. Para evitar que se desplacen los controles de paginación, el componente TablePagination se usa fuera de la Tabla. (El ejemplo de la 'Acción de paginación de tabla personalizado' de abajo demuestra la paginación dentro del TableFooter.)
Dessert (100g serving) | Caloriessorted ascending | Fat (g) | Carbs (g) | Protein (g) | |
---|---|---|---|---|---|
Frozen yoghurt | 159 | 6 | 24 | 4 | |
Ice cream sandwich | 237 | 9 | 37 | 4.3 | |
Eclair | 262 | 16 | 24 | 6 | |
Cupcake | 305 | 3.7 | 67 | 4.3 | |
Marshmallow | 318 | 0 | 81 | 2 |
Tablas personalizadas
Here is an example of customizing the component. You can learn more about this in the overrides documentation page.
Dessert (100g serving) | Calories | Fat (g) | Carbs (g) | Protein (g) |
---|---|---|---|---|
Frozen yoghurt | 159 | 6 | 24 | 4 |
Ice cream sandwich | 237 | 9 | 37 | 4.3 |
Eclair | 262 | 16 | 24 | 6 |
Cupcake | 305 | 3.7 | 67 | 4.3 |
Gingerbread | 356 | 16 | 49 | 3.9 |
Opciones de paginación personalizada
Es posible personalizar las opciones en el item "Filas por página" usando la propiedad rowsPerPageOptions
. Debes proveer alguna de estas opciones de array:
numbers, cada número será usado para la etiqueta y el valor de la opción.
<TablePagination rowsPerPageOptions={[10, 50]} />
objects, the
value
andlabel
keys will be used respectively for the value and label of the option (useful for language strings such as 'All').<TablePagination rowsPerPageOptions={[10, 50, { value: -1, label: 'All' }]} />
Custom pagination actions
El atributo Action
del componente TablePagination
permite implementar acciones personalizadas.
Frozen yoghurt | 159 | 6 |
---|---|---|
Ice cream sandwich | 237 | 9 |
Eclair | 262 | 16 |
Cupcake | 305 | 3.7 |
Marshmallow | 318 | 0 |
Fixed header
An example of a table with scrollable rows and fixed column headers. It leverages the stickyHeader
prop (⚠️ no IE 11 support).
Name | ISO Code | Population | Size (km²) | Density |
---|---|---|---|---|
India | IN | 1,324,171,354 | 3,287,263 | 402.82 |
China | CN | 1,403,500,365 | 9,596,961 | 146.24 |
Italy | IT | 60,483,973 | 301,340 | 200.72 |
United States | US | 327,167,434 | 9,833,520 | 33.27 |
Canada | CA | 37,602,103 | 9,984,670 | 3.77 |
Australia | AU | 25,475,400 | 7,692,024 | 3.31 |
Germany | DE | 83,019,200 | 357,578 | 232.17 |
Ireland | IE | 4,857,000 | 70,273 | 69.12 |
Mexico | MX | 126,577,691 | 1,972,550 | 64.17 |
Japan | JP | 126,317,000 | 377,973 | 334.20 |
Details | Price | ||
---|---|---|---|
Desc | Qty. | Unit | Sum |
Paperclips (Box) | 100 | 1.15 | 115.00 |
Paper (Case) | 10 | 45.99 | 459.90 |
Waste Basket | 2 | 17.99 | 35.98 |
Subtotal | 610.88 | ||
Tax | 7 % | 42.76 | |
Total | 653.64 |
Tabla Virtualizada
En el siguiente ejemplo, demostramos como usar react-virtualized con el componente Table
. Renderiza 200 filas y fácilmente puede manejar más. La virtualización ayuda con problemas de rendimiento.
Proyectos relacionados
Para usos más avanzados tal vez puedas aprovercharte de:
material-table
material-table is a simple and powerful Datatable for React based on Material-UI Table with some additional features. They support many different use cases (editable, filtering, grouping, sorting, selection, i18n, tree data and more). You should check it out.
Actions | Name | Surname | Birth Year | Birth Place |
---|---|---|---|---|
Mehmet | Baran | 1987 | Şanlıurfa | |
Zerya Betül | Baran | 2017 | İstanbul | |
Otros
- dx-react-grid-material-ui: A data grid for Material-UI with paging, sorting, filtering, grouping and editing features (paid license).
- mui-datatables: Responsive data tables for Material-UI with filtering, sorting, search and more.
- tubular-react: A Material-UI table with local or remote data-source. Featuring filtering, sorting, free-text search, export to CSV locally, and aggregations.
Accesibilidad
(WAI tutorial: https://www.w3.org/WAI/tutorials/tables/)
Caption
A caption functions like a heading for a table. Most screen readers announce the content of captions. Captions help users to find a table and understand what it’s about and decide if they want to read it.
Dessert (100g serving) | Calories | Fat (g) | Carbs (g) | Protein (g) |
---|---|---|---|---|
Frozen yoghurt | 159 | 6 | 24 | 4 |
Ice cream sandwich | 237 | 9 | 37 | 4.3 |
Eclair | 262 | 16 | 24 | 6 |