---
url: https://vue-ds.fr/composants/DsfrTableHeaders.md
---
# En-têtes de tableau

## 🌟 Introduction

Bienvenue dans la documentation du composant `DsfrTableHeaders`! Ce composant est comme le maestro d'un orchestre, orchestrant l'affichage des en-têtes de vos tableaux Vue avec élégance et précision. Allons-y pour découvrir ses caractéristiques.

🏅 La documentation sur le tableau sur le [DSFR](https://www.systeme-de-design.gouv.fr/version-courante/fr/composants/tableau/)

&#x20;La story sur les en-têtes de tableau sur le storybook de [VueDsfr](https://storybook.vue-ds.fr/?path=/docs/composants-dsfrtableheaders--docs)

## 🛠️ Props

| Nom       | Type                        | Défaut | Obligatoire | Description                                                          |
|-----------|-----------------------------|--------|-------------|----------------------------------------------------------------------|
| `headers` | `DsfrTableHeadersProps`     |        | ✅           | Un tableau d'objets ou de chaînes représentant les en-têtes du tableau. |

### Description des Types

* **`DsfrTableHeadersProps`**: Un tableau composé d'objets ou de chaînes. Un objet peut avoir une propriété `text` (chaîne) pour le texte de l'en-tête et `headerAttrs` (objet) pour les attributs HTML supplémentaires à appliquer sur l'en-tête.

## 🧩 Slots

Pas de slots spécifiques pour ce composant. Il s'agit principalement d'un composant utilitaire pour `DsfrTable`.

## 📝 Exemples

### Exemple Basique

```vue
<DsfrTableHeaders :headers="['Nom', 'Age', 'Ville']" />
```

### Exemple avec Attributs Supplémentaires

::: code-group

```vue
<script setup lang="ts">
import type { DsfrTableRowProps } from '../DsfrTable.types'

import DsfrTable from '../DsfrTable.vue'
import DsfrTableHeaders from '../DsfrTableHeaders.vue'

const title = 'Exemple de tableau avec entêtes personnalisées'
const rows: DsfrTableRowProps[] = [
  { rowData: ['Alice', '30', 'Paris'] },
  { rowData: ['Bob', '24', 'Lyon'] },
]
</script>

<template>
  <DsfrTable
    :title="title"
    :rows="rows"
    class="w-full"
  >
    <template #header>
      <DsfrTableHeaders
        :headers="[
          { text: 'Nom', headerAttrs: { class: 'header-nom' } },
          { text: 'Age', headerAttrs: { class: 'header-age' } },
          'Ville',
        ]"
      />
    </template>
  </DsfrTable>
</template>

<style scoped>
:deep(.fr-table table) {
  table-layout: fixed;
}
</style>

```

:::

::: tip Petit conseil

Utiliser des objets pour les en-têtes vous permet d'ajouter des classes CSS ou d'autres attributs pour personnaliser davantage vos en-têtes!

:::

## ⚙️ Code source du composant

::: code-group

```ts
import type VIcon from '../VIcon/VIcon.vue'
import type { HTMLAttributes, TdHTMLAttributes, ThHTMLAttributes } from 'vue'

export type DsfrTableRowProps = {
  rowData?: (string | Record<string, any>)[]
  rowAttrs?: HTMLAttributes
}

export type DsfrTableHeaderProps = {
  header?: string
  headerAttrs?: ThHTMLAttributes & { onClick?: (e: MouseEvent) => void }
  icon?: string | InstanceType<typeof VIcon>['$props']
}

export type DsfrTableHeadersProps = (string | (DsfrTableHeaderProps & { text?: string }))[]

export type DsfrTableCellProps = {
  field: string | Record<string, unknown>
  cellAttrs?: TdHTMLAttributes
  component?: string
  text?: string
  title?: string
  class?: string
  onClick?: Promise<void>
}

export type DsfrTableProps = {
  title: string
  headers?: DsfrTableHeadersProps
  rows?: (DsfrTableRowProps | (DsfrTableCellProps | { component: string, [k: string]: unknown } | string)[])[]

  rowKey?: ((row: (string | Record<string, any>)[] | undefined) => string | number | symbol | undefined) | string
  noCaption?: boolean
  pagination?: boolean
  currentPage?: number
  resultsDisplayed?: number
}

```

:::

Voilà, chers développeurs, prêts à rendre vos tableaux encore plus impressionnants avec `DsfrTableHeaders` ! 🌟
