ComponentesComponents

TablaTable

Tabla con orden por columna y desplazamiento horizontal en móvil.Table with column sorting and horizontal scroll on mobile.

DiseñoDesign: coss ui (MIT) · table.tsxMITherramienta · densidaddensity alta · sobriaMarkdownJSON

CódigoCode

<div class="c-table-wrap" role="region" aria-labelledby="tbl-caption" tabindex="0">
  <table class="c-table" data-c-sortable>
    <caption class="c-table__caption c-sr-only" id="tbl-caption">Facturas de septiembre 2026</caption>
    <thead>
      <tr>
        <th class="c-table__head" scope="col" aria-sort="descending"><button class="c-table__sort" type="button" data-key="0">Factura <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m18 15-6-6-6 6"/></svg></button></th>
        <th class="c-table__head" scope="col"><button class="c-table__sort" type="button" data-key="1">Cliente <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m18 15-6-6-6 6"/></svg></button></th>
        <th class="c-table__head" scope="col">Estado</th>
        <th class="c-table__head c-table__head--num" scope="col"><button class="c-table__sort" type="button" data-key="3" data-type="num">Monto <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m18 15-6-6-6 6"/></svg></button></th>
      </tr>
    </thead>
    <tbody>
      <tr class="c-table__row"><td class="c-table__cell">INV-0914</td><td class="c-table__cell">Northwind</td><td class="c-table__cell"><span class="c-badge c-badge--success"><span class="c-badge__dot" aria-hidden="true"></span>Pagado</span></td><td class="c-table__cell c-table__cell--num" data-value="89">S/ 89.00</td></tr>
      <tr class="c-table__row"><td class="c-table__cell">INV-0913</td><td class="c-table__cell">Vela Labs</td><td class="c-table__cell"><span class="c-badge c-badge--success"><span class="c-badge__dot" aria-hidden="true"></span>Pagado</span></td><td class="c-table__cell c-table__cell--num" data-value="249">S/ 249.00</td></tr>
      <tr class="c-table__row"><td class="c-table__cell">INV-0912</td><td class="c-table__cell">Tallyworks</td><td class="c-table__cell"><span class="c-badge c-badge--warning"><span class="c-badge__dot" aria-hidden="true"></span>Pendiente</span></td><td class="c-table__cell c-table__cell--num" data-value="29">S/ 29.00</td></tr>
      <tr class="c-table__row"><td class="c-table__cell">INV-0911</td><td class="c-table__cell">Harbor &amp; Co</td><td class="c-table__cell"><span class="c-badge c-badge--error"><span class="c-badge__dot" aria-hidden="true"></span>Vencido</span></td><td class="c-table__cell c-table__cell--num" data-value="101">S/ 101.00</td></tr>
    </tbody>
  </table>
</div>
<p class="c-sr-only" role="status" data-c-table-status></p>

«Todo» trae tokens, dependencias y componente en un solo archivo, listo para abrir o dárselo a un agente.“All” bundles tokens, dependencies and the component in one file, ready to open or hand to an agent.

InstalaciónInstallation

  1. Agrega una vezAdd once tokens.css (colores, radios, tema oscuro).(colors, radii, dark theme).
  2. Agrega también:Also add: Badge.
  3. Copia los archivos:Copy the files: table.html, table.css, table.js.
  4. Para el tema oscuro, pon la claseFor the dark theme, add the class dark ento <html>.

Cuándo usarloWhen to use it

ÚsaloUse it

  • Para datos que se comparan por filas y columnas.
  • For data compared by rows and columns.

Mejor noAvoid

  • Para maquetar: usa grid.
  • For layout: use grid.

AccesibilidadAccessibility

tablecolumnheaderbutton
TabLlega a los botones de ordenReaches the sort buttons
Enter EspacioOrdena la columnaSorts the column
  • Para ordenar, un botón dentro del encabezado y aria-sort en la columna.
  • El contenedor se desplaza con teclado (tabindex=0 y nombre).
  • To sort, a button inside the header and aria-sort on the column.
  • The wrapper scrolls with the keyboard (tabindex=0 and a name).

Cómo probarloHow to test it

  • Pulsa «Monto»: se ordena ascendente y se anuncia.
  • Press “Amount”: it sorts ascending and is announced.

CréditosCredits