# Table

Displays a data table. Note: This component is a wrapper of the Bootstrap-Vue Table component (opens new window).

# Example

Left Column
(Click to sort Ascending)
Center Column
(Click to sort Ascending)
Right Column
(Click to sort Ascending)
Sort-Disabled Column
Custom Cell Render
(Click to sort Ascending)
Drilldown
1 testa testtesttestlink1
2 testb testtesttestlink2
3 testc testtesttestlink3
4 testd testtesttestlink4
5 teste testtesttestlink5

Code:

<template>
  <div class="margin-top-2">
    <Table :columns="columns" :rows="rows" :shouldDisplayFilter="true" breakpoint="680px" >
      <!-- Custom cell render slot -->
      <template v-slot:cell(Column5)="data">
        <a href="#">{{ data.value }}</a>
      </template>

      <!-- Row drilldown/details functionality -->
      <template v-slot:cell(Column6)="row">
        <Button label="Drilldown" @click="row.toggleDetails" />
      </template>

      <template v-slot:row-details="row">
        <Alert type="warning" :text="row.item.Column2" />
      </template>
    </Table>
  </div>
</template>

<script>
export default {
  data() {
    return {
      columns: [
        { key: 'Column1', label: 'Left Column', tdClass: 'text-left' },
        { key: 'Column2', label: 'Center Column', hideOnBreakpoint: 'tablet-lg' },
        { key: 'Column3', label: 'Right Column', tdClass: 'text-right', hideOnBreakpoint: 'desktop' },
        { key: 'Column4', label: 'Sort-Disabled Column', sortable: false },
        { key: 'Column5', label: 'Custom Cell Render' },
        { key: 'Column6', label: 'Drilldown', sortable: false },
      ],
      rows: [
        { Column1: '1 test', Column2: 'a test', Column3: 'test', Column4: 'test', Column5: 'link1', Column6: 'test' },
        { Column1: '2 test', Column2: 'b test', Column3: 'test', Column4: 'test', Column5: 'link2', Column6: 'test' },
        { Column1: '3 test', Column2: 'c test', Column3: 'test', Column4: 'test', Column5: 'link3', Column6: 'test' },
        { Column1: '4 test', Column2: 'd test', Column3: 'test', Column4: 'test', Column5: 'link4', Column6: 'test' },
        { Column1: '5 test', Column2: 'e test', Column3: 'test', Column4: 'test', Column5: 'link5', Column6: 'test' },
      ],
    };
  },
};
</script>

# Props

*Required

Name Type Description Default
columns* Array For a simple table, this can be an array of strings for column headers. Otherwise, use an array of objects (see below)
rows* Array Array of objects with the object keys matching column keys.
defaultSort String Set the column key that should be sorted on by default.
busy Boolean If true, table will display a loading indicator. Used when fetching data. false
shouldDisplayFilter Boolean Displays a text filter to search table's content. false

# Columns Array

hideOnBreakpoint

Add hideOnBreakpoint prop to field object to hide specific columns depending on screen size. Currently available breakpoints (following USWDS) are below. Use the screen type as the value of hideOnBreakpoint, e.g. hideOnBreakpoint: 'tablet'

  • desktop-lg - 1200px
  • desktop - 1040px
  • tablet-lg - 800px
  • tablet - 640px

See the Bootstrap-Vue Table fields documentation (opens new window) for how to build the field objects.