React Bootstrap docs

Tables

Examples for opt-in styling of tables, alongside searching and sorting features.

The table search and sorting feature is enabled through the TanStack Table library. Ensure that you have imported all necessary files, as demonstrated in the code snippet of the respective component section.

Basic example

#FirstLastPositionPhone
1JohnDoeCEO, Founder+3 555 68 70
2AnnaCabanaDesigner+3 434 65 93
3KaleThorntonDeveloper+3 285 42 88
4JaneBirkinsSupport+3 774 28 50
import Table from 'react-bootstrap/Table'

export default function TableBasicDemo() {
  return (
    <Table responsive>
      <thead>
        <tr>
          <th scope="col">#</th>
          <th scope="col">First</th>
          <th scope="col">Last</th>
          <th scope="col">Position</th>
          <th scope="col">Phone</th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <th scope="row">1</th>
          <td>John</td>
          <td>Doe</td>
          <td>CEO, Founder</td>
          <td className="text-nowrap">+3 555 68 70</td>
        </tr>
        <tr>
          <th scope="row">2</th>
          <td>Anna</td>
          <td>Cabana</td>
          <td>Designer</td>
          <td className="text-nowrap">+3 434 65 93</td>
        </tr>
        <tr>
          <th scope="row">3</th>
          <td>Kale</td>
          <td>Thornton</td>
          <td>Developer</td>
          <td className="text-nowrap">+3 285 42 88</td>
        </tr>
        <tr>
          <th scope="row">4</th>
          <td>Jane</td>
          <td>Birkins</td>
          <td>Support</td>
          <td className="text-nowrap">+3 774 28 50</td>
        </tr>
      </tbody>
    </Table>
  )
}

Sorting

#
First
Last
Position
Phone
1JohnDoeCEO, Founder+3 555 68 70
2AnnaCabanaDesigner+3 434 65 93
3KaleThorntonDeveloper+3 285 42 88
4JaneBirkinsSupport+3 774 28 50
5RobertSmithMarketing+3 623 87 19
6EmilyJohnsonSales+3 911 50 62
7MatthewBrownAnalyst+3 329 49 75
8OliviaDavisFinance+3 146 91 27
9WilliamGarciaProject Manager+3 509 76 39
10SophiaAdamsHR+3 687 25 81
'use client'

import { useState, useMemo } from 'react'
import DocsComponentDemo from '@/components/docs/docs-component-demo'
import Table from 'react-bootstrap/Table'
import {
  ColumnDef,
  flexRender,
  getCoreRowModel,
  getSortedRowModel,
  SortingState,
  useReactTable,
} from '@tanstack/react-table'

type Person = {
  id: number
  firstName: string
  lastName: string
  position: string
  phone: string
}

export default function TableSortingDemo() {
  const columns = useMemo<ColumnDef<Person>[]>(
    () => [
      {
        accessorKey: 'id',
        cell: (info) => info.getValue(),
        header: '#',
        sortingFn: 'alphanumeric',
      },
      {
        accessorKey: 'firstName',
        cell: (info) => info.getValue(),
        header: 'First',
        sortingFn: 'textCaseSensitive',
      },
      {
        accessorKey: 'lastName',
        cell: (info) => info.getValue(),
        header: 'Last',
        sortingFn: 'textCaseSensitive',
      },
      {
        accessorKey: 'position',
        cell: (info) => info.getValue(),
        header: 'Position',
        sortingFn: 'textCaseSensitive',
      },
      {
        accessorKey: 'phone',
        cell: (info) => info.getValue(),
        header: 'Phone',
        enableSorting: false,
      },
    ],
    []
  )

  const persons: Person[] = [
    { id: 1, firstName: 'John', lastName: 'Doe', position: 'CEO, Founder', phone: '+3 555 68 70' },
    { id: 2, firstName: 'Anna', lastName: 'Cabana', position: 'Designer', phone: '+3 434 65 93' },
    { id: 3, firstName: 'Kale', lastName: 'Thornton', position: 'Developer', phone: '+3 285 42 88' },
    { id: 4, firstName: 'Jane', lastName: 'Birkins', position: 'Support', phone: '+3 774 28 50' },
    { id: 5, firstName: 'Robert', lastName: 'Smith', position: 'Marketing', phone: '+3 623 87 19' },
    { id: 6, firstName: 'Emily', lastName: 'Johnson', position: 'Sales', phone: '+3 911 50 62' },
    { id: 7, firstName: 'Matthew', lastName: 'Brown', position: 'Analyst', phone: '+3 329 49 75' },
    { id: 8, firstName: 'Olivia', lastName: 'Davis', position: 'Finance', phone: '+3 146 91 27' },
    { id: 9, firstName: 'William', lastName: 'Garcia', position: 'Project Manager', phone: '+3 509 76 39' },
    { id: 10, firstName: 'Sophia', lastName: 'Adams', position: 'HR', phone: '+3 687 25 81' },
  ]

  const [data, setData] = useState<Person[]>(persons)
  const [sorting, setSorting] = useState<SortingState>([])
  const table = useReactTable({
    columns,
    data,
    getCoreRowModel: getCoreRowModel(),
    getSortedRowModel: getSortedRowModel(),
    onSortingChange: setSorting,
    state: {
      sorting,
    },
    filterFns: {
      fuzzy: () => true,
    },
  })

  return (
    <div className="table-responsive overflow-auto" style={{ height: 300 }}>
      <Table>
        <thead className="position-sticky top-0">
          {table.getHeaderGroups().map((headerGroup) => (
            <tr key={headerGroup.id}>
              {headerGroup.headers.map((header) => (
                <th key={header.id} colSpan={header.colSpan}>
                  {header.isPlaceholder ? null : (
                    <>
                      {header.column.getCanSort() ? (
                        <div
                          className={header.column.getCanSort() ? 'cursor-pointer text-nowrap select-none' : ''}
                          onClick={header.column.getToggleSortingHandler()}
                          title={
                            header.column.getCanSort()
                              ? header.column.getNextSortingOrder() === 'asc'
                                ? 'Sort ascending'
                                : header.column.getNextSortingOrder() === 'desc'
                                  ? 'Sort descending'
                                  : 'Clear sorting'
                              : undefined
                          }
                        >
                          {flexRender(header.column.columnDef.header, header.getContext())}
                          <span className="fs-sm opacity-75 ms-1">
                            {' '}
                            {{ asc: '↑', desc: '↓' }[header.column.getIsSorted() as string] ?? (
                              <i className="ci-sort align-middle" />
                            )}
                          </span>
                        </div>
                      ) : (
                        flexRender(header.column.columnDef.header, header.getContext())
                      )}
                    </>
                  )}
                </th>
              ))}
            </tr>
          ))}
        </thead>
        <tbody>
          {table.getRowModel().rows.map((row) => (
            <tr key={row.id}>
              {row.getVisibleCells().map((cell) => (
                <td key={cell.id}>{flexRender(cell.column.columnDef.cell, cell.getContext())}</td>
              ))}
            </tr>
          ))}
        </tbody>
      </Table>
    </div>
  )
}

Dark table

#FirstLastPositionPhone
1JohnDoeCEO, Founder+3 555 68 70
2AnnaCabanaDesigner+3 434 65 93
3KaleThorntonDeveloper+3 285 42 88
4JaneBirkinsSupport+3 774 28 50
import Table from 'react-bootstrap/Table'

export default function TableDarkDemo() {
  return (
    <Table variant="dark" responsive>
      <thead>
        <tr>
          <th scope="col">#</th>
          <th scope="col">First</th>
          <th scope="col">Last</th>
          <th scope="col">Position</th>
          <th scope="col">Phone</th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <th scope="row">1</th>
          <td>John</td>
          <td>Doe</td>
          <td>CEO, Founder</td>
          <td className="text-nowrap">+3 555 68 70</td>
        </tr>
        <tr>
          <th scope="row">2</th>
          <td>Anna</td>
          <td>Cabana</td>
          <td>Designer</td>
          <td className="text-nowrap">+3 434 65 93</td>
        </tr>
        <tr>
          <th scope="row">3</th>
          <td>Kale</td>
          <td>Thornton</td>
          <td>Developer</td>
          <td className="text-nowrap">+3 285 42 88</td>
        </tr>
        <tr>
          <th scope="row">4</th>
          <td>Jane</td>
          <td>Birkins</td>
          <td>Support</td>
          <td className="text-nowrap">+3 774 28 50</td>
        </tr>
      </tbody>
    </Table>
  )
}

Striped rows

#FirstLastPositionPhone
1JohnDoeCEO, Founder+3 555 68 70
2AnnaCabanaDesigner+3 434 65 93
3KaleThorntonDeveloper+3 285 42 88
#FirstLastPositionPhone
1JohnDoeCEO, Founder+3 555 68 70
2AnnaCabanaDesigner+3 434 65 93
3KaleThorntonDeveloper+3 285 42 88
import Table from 'react-bootstrap/Table'

export default function TableStripedRowsDemo() {
  return (
    <>
      <Table striped responsive>
        <thead>
          <tr>
            <th scope="col">#</th>
            <th scope="col">First</th>
            <th scope="col">Last</th>
            <th scope="col">Position</th>
            <th scope="col">Phone</th>
          </tr>
        </thead>
        <tbody>
          <tr>
            <th scope="row">1</th>
            <td>John</td>
            <td>Doe</td>
            <td>CEO, Founder</td>
            <td className="text-nowrap">+3 555 68 70</td>
          </tr>
          <tr>
            <th scope="row">2</th>
            <td>Anna</td>
            <td>Cabana</td>
            <td>Designer</td>
            <td className="text-nowrap">+3 434 65 93</td>
          </tr>
          <tr>
            <th scope="row">3</th>
            <td>Kale</td>
            <td>Thornton</td>
            <td>Developer</td>
            <td className="text-nowrap">+3 285 42 88</td>
          </tr>
        </tbody>
      </Table>

      <Table variant="dark" striped responsive>
        <thead>
          <tr>
            <th scope="col">#</th>
            <th scope="col">First</th>
            <th scope="col">Last</th>
            <th scope="col">Position</th>
            <th scope="col">Phone</th>
          </tr>
        </thead>
        <tbody>
          <tr>
            <th scope="row">1</th>
            <td>John</td>
            <td>Doe</td>
            <td>CEO, Founder</td>
            <td className="text-nowrap">+3 555 68 70</td>
          </tr>
          <tr>
            <th scope="row">2</th>
            <td>Anna</td>
            <td>Cabana</td>
            <td>Designer</td>
            <td className="text-nowrap">+3 434 65 93</td>
          </tr>
          <tr>
            <th scope="row">3</th>
            <td>Kale</td>
            <td>Thornton</td>
            <td>Developer</td>
            <td className="text-nowrap">+3 285 42 88</td>
          </tr>
        </tbody>
      </Table>
    </>
  )
}

Striped columns

#FirstLastPositionPhone
1JohnDoeCEO, Founder+3 555 68 70
2AnnaCabanaDesigner+3 434 65 93
3KaleThorntonDeveloper+3 285 42 88
#FirstLastPositionPhone
1JohnDoeCEO, Founder+3 555 68 70
2AnnaCabanaDesigner+3 434 65 93
3KaleThorntonDeveloper+3 285 42 88
import Table from 'react-bootstrap/Table'

export default function TableStripedColsDemo() {
  return (
    <>
      <Table striped="columns" responsive>
        <thead>
          <tr>
            <th scope="col">#</th>
            <th scope="col">First</th>
            <th scope="col">Last</th>
            <th scope="col">Position</th>
            <th scope="col">Phone</th>
          </tr>
        </thead>
        <tbody>
          <tr>
            <th scope="row">1</th>
            <td>John</td>
            <td>Doe</td>
            <td>CEO, Founder</td>
            <td className="text-nowrap">+3 555 68 70</td>
          </tr>
          <tr>
            <th scope="row">2</th>
            <td>Anna</td>
            <td>Cabana</td>
            <td>Designer</td>
            <td className="text-nowrap">+3 434 65 93</td>
          </tr>
          <tr>
            <th scope="row">3</th>
            <td>Kale</td>
            <td>Thornton</td>
            <td>Developer</td>
            <td className="text-nowrap">+3 285 42 88</td>
          </tr>
        </tbody>
      </Table>

      <Table variant="dark" striped="columns" responsive>
        <thead>
          <tr>
            <th scope="col">#</th>
            <th scope="col">First</th>
            <th scope="col">Last</th>
            <th scope="col">Position</th>
            <th scope="col">Phone</th>
          </tr>
        </thead>
        <tbody>
          <tr>
            <th scope="row">1</th>
            <td>John</td>
            <td>Doe</td>
            <td>CEO, Founder</td>
            <td className="text-nowrap">+3 555 68 70</td>
          </tr>
          <tr>
            <th scope="row">2</th>
            <td>Anna</td>
            <td>Cabana</td>
            <td>Designer</td>
            <td className="text-nowrap">+3 434 65 93</td>
          </tr>
          <tr>
            <th scope="row">3</th>
            <td>Kale</td>
            <td>Thornton</td>
            <td>Developer</td>
            <td className="text-nowrap">+3 285 42 88</td>
          </tr>
        </tbody>
      </Table>
    </>
  )
}

Bordered table

#FirstLastPositionPhone
1JohnDoeCEO, Founder+3 555 68 70
2AnnaCabanaDesigner+3 434 65 93
3KaleThorntonDeveloper+3 285 42 88
#FirstLastPositionPhone
1JohnDoeCEO, Founder+3 555 68 70
2AnnaCabanaDesigner+3 434 65 93
3KaleThorntonDeveloper+3 285 42 88
import Table from 'react-bootstrap/Table'

export default function TableBorderedDemo() {
  return (
    <>
      <Table bordered responsive>
        <thead>
          <tr>
            <th scope="col">#</th>
            <th scope="col">First</th>
            <th scope="col">Last</th>
            <th scope="col">Position</th>
            <th scope="col">Phone</th>
          </tr>
        </thead>
        <tbody>
          <tr>
            <th scope="row">1</th>
            <td>John</td>
            <td>Doe</td>
            <td>CEO, Founder</td>
            <td className="text-nowrap">+3 555 68 70</td>
          </tr>
          <tr>
            <th scope="row">2</th>
            <td>Anna</td>
            <td>Cabana</td>
            <td>Designer</td>
            <td className="text-nowrap">+3 434 65 93</td>
          </tr>
          <tr>
            <th scope="row">3</th>
            <td>Kale</td>
            <td>Thornton</td>
            <td>Developer</td>
            <td className="text-nowrap">+3 285 42 88</td>
          </tr>
        </tbody>
      </Table>

      <Table variant="dark" bordered responsive>
        <thead>
          <tr>
            <th scope="col">#</th>
            <th scope="col">First</th>
            <th scope="col">Last</th>
            <th scope="col">Position</th>
            <th scope="col">Phone</th>
          </tr>
        </thead>
        <tbody>
          <tr>
            <th scope="row">1</th>
            <td>John</td>
            <td>Doe</td>
            <td>CEO, Founder</td>
            <td className="text-nowrap">+3 555 68 70</td>
          </tr>
          <tr>
            <th scope="row">2</th>
            <td>Anna</td>
            <td>Cabana</td>
            <td>Designer</td>
            <td className="text-nowrap">+3 434 65 93</td>
          </tr>
          <tr>
            <th scope="row">3</th>
            <td>Kale</td>
            <td>Thornton</td>
            <td>Developer</td>
            <td className="text-nowrap">+3 285 42 88</td>
          </tr>
        </tbody>
      </Table>
    </>
  )
}

Table without borders

#FirstLastPositionPhone
1JohnDoeCEO, Founder+3 555 68 70
2AnnaCabanaDesigner+3 434 65 93
3KaleThorntonDeveloper+3 285 42 88
#FirstLastPositionPhone
1JohnDoeCEO, Founder+3 555 68 70
2AnnaCabanaDesigner+3 434 65 93
3KaleThorntonDeveloper+3 285 42 88
import Table from 'react-bootstrap/Table'

export default function TableBorderlessDemo() {
  return (
    <>
      <Table borderless responsive>
        <thead>
          <tr>
            <th scope="col">#</th>
            <th scope="col">First</th>
            <th scope="col">Last</th>
            <th scope="col">Position</th>
            <th scope="col">Phone</th>
          </tr>
        </thead>
        <tbody>
          <tr>
            <th scope="row">1</th>
            <td>John</td>
            <td>Doe</td>
            <td>CEO, Founder</td>
            <td className="text-nowrap">+3 555 68 70</td>
          </tr>
          <tr>
            <th scope="row">2</th>
            <td>Anna</td>
            <td>Cabana</td>
            <td>Designer</td>
            <td className="text-nowrap">+3 434 65 93</td>
          </tr>
          <tr>
            <th scope="row">3</th>
            <td>Kale</td>
            <td>Thornton</td>
            <td>Developer</td>
            <td className="text-nowrap">+3 285 42 88</td>
          </tr>
        </tbody>
      </Table>

      <Table variant="dark" borderless responsive>
        <thead>
          <tr>
            <th scope="col">#</th>
            <th scope="col">First</th>
            <th scope="col">Last</th>
            <th scope="col">Position</th>
            <th scope="col">Phone</th>
          </tr>
        </thead>
        <tbody>
          <tr>
            <th scope="row">1</th>
            <td>John</td>
            <td>Doe</td>
            <td>CEO, Founder</td>
            <td className="text-nowrap">+3 555 68 70</td>
          </tr>
          <tr>
            <th scope="row">2</th>
            <td>Anna</td>
            <td>Cabana</td>
            <td>Designer</td>
            <td className="text-nowrap">+3 434 65 93</td>
          </tr>
          <tr>
            <th scope="row">3</th>
            <td>Kale</td>
            <td>Thornton</td>
            <td>Developer</td>
            <td className="text-nowrap">+3 285 42 88</td>
          </tr>
        </tbody>
      </Table>
    </>
  )
}

Hoverable rows

#FirstLastPositionPhone
1JohnDoeCEO, Founder+3 555 68 70
2AnnaCabanaDesigner+3 434 65 93
3KaleThorntonDeveloper+3 285 42 88
#FirstLastPositionPhone
1JohnDoeCEO, Founder+3 555 68 70
2AnnaCabanaDesigner+3 434 65 93
3KaleThorntonDeveloper+3 285 42 88
import Table from 'react-bootstrap/Table'

export default function TableHoverableDemo() {
  return (
    <>
      <Table hover responsive>
        <thead>
          <tr>
            <th scope="col">#</th>
            <th scope="col">First</th>
            <th scope="col">Last</th>
            <th scope="col">Position</th>
            <th scope="col">Phone</th>
          </tr>
        </thead>
        <tbody>
          <tr>
            <th scope="row">1</th>
            <td>John</td>
            <td>Doe</td>
            <td>CEO, Founder</td>
            <td className="text-nowrap">+3 555 68 70</td>
          </tr>
          <tr>
            <th scope="row">2</th>
            <td>Anna</td>
            <td>Cabana</td>
            <td>Designer</td>
            <td className="text-nowrap">+3 434 65 93</td>
          </tr>
          <tr>
            <th scope="row">3</th>
            <td>Kale</td>
            <td>Thornton</td>
            <td>Developer</td>
            <td className="text-nowrap">+3 285 42 88</td>
          </tr>
        </tbody>
      </Table>

      <Table variant="dark" hover responsive>
        <thead>
          <tr>
            <th scope="col">#</th>
            <th scope="col">First</th>
            <th scope="col">Last</th>
            <th scope="col">Position</th>
            <th scope="col">Phone</th>
          </tr>
        </thead>
        <tbody>
          <tr>
            <th scope="row">1</th>
            <td>John</td>
            <td>Doe</td>
            <td>CEO, Founder</td>
            <td className="text-nowrap">+3 555 68 70</td>
          </tr>
          <tr>
            <th scope="row">2</th>
            <td>Anna</td>
            <td>Cabana</td>
            <td>Designer</td>
            <td className="text-nowrap">+3 434 65 93</td>
          </tr>
          <tr>
            <th scope="row">3</th>
            <td>Kale</td>
            <td>Thornton</td>
            <td>Developer</td>
            <td className="text-nowrap">+3 285 42 88</td>
          </tr>
        </tbody>
      </Table>
    </>
  )
}

Contextual colors

#ClassHeadingHeading
1PrimaryColumn contentColumn content
2SecondaryColumn contentColumn content
3SuccessColumn contentColumn content
4InfoColumn contentColumn content
5WarningColumn contentColumn content
6DangerColumn contentColumn content
7LghtColumn contentColumn content
8DarkColumn contentColumn content
import Table from 'react-bootstrap/Table'

export default function TableContextualDemo() {
  return (
    <Table responsive style={{ '--cz-table-bg': 'transparent' } as React.CSSProperties}>
      <thead>
        <tr>
          <th scope="col">#</th>
          <th scope="col">Class</th>
          <th scope="col">Heading</th>
          <th scope="col">Heading</th>
        </tr>
      </thead>
      <tbody>
        <tr className="bg-primary-subtle">
          <th scope="row">1</th>
          <td>Primary</td>
          <td>Column content</td>
          <td>Column content</td>
        </tr>
        <tr className="bg-secondary-subtle">
          <th scope="row">2</th>
          <td>Secondary</td>
          <td>Column content</td>
          <td>Column content</td>
        </tr>
        <tr className="bg-success-subtle">
          <th scope="row">3</th>
          <td>Success</td>
          <td>Column content</td>
          <td>Column content</td>
        </tr>
        <tr className="bg-info-subtle">
          <th scope="row">4</th>
          <td>Info</td>
          <td>Column content</td>
          <td>Column content</td>
        </tr>
        <tr className="bg-warning-subtle">
          <th scope="row">5</th>
          <td>Warning</td>
          <td>Column content</td>
          <td>Column content</td>
        </tr>
        <tr className="bg-danger-subtle">
          <th scope="row">6</th>
          <td>Danger</td>
          <td>Column content</td>
          <td>Column content</td>
        </tr>
        <tr className="bg-light-subtle">
          <th scope="row">7</th>
          <td>Lght</td>
          <td>Column content</td>
          <td>Column content</td>
        </tr>
        <tr className="bg-dark-subtle">
          <th scope="row">8</th>
          <td>Dark</td>
          <td>Column content</td>
          <td>Column content</td>
        </tr>
      </tbody>
    </Table>
  )
}

Color borders

#FirstLastPositionPhone
1JohnDoeCEO, Founder+3 555 68 70
2AnnaCabanaDesigner+3 434 65 93
#FirstLastPositionPhone
1JohnDoeCEO, Founder+3 555 68 70
2AnnaCabanaDesigner+3 434 65 93
import Table from 'react-bootstrap/Table'

export default function TableColorBordersDemo() {
  return (
    <>
      <Table bordered responsive className="border-info">
        <thead>
          <tr>
            <th scope="col">#</th>
            <th scope="col">First</th>
            <th scope="col">Last</th>
            <th scope="col">Position</th>
            <th scope="col">Phone</th>
          </tr>
        </thead>
        <tbody>
          <tr>
            <th scope="row">1</th>
            <td>John</td>
            <td>Doe</td>
            <td>CEO, Founder</td>
            <td className="text-nowrap">+3 555 68 70</td>
          </tr>
          <tr>
            <th scope="row">2</th>
            <td>Anna</td>
            <td>Cabana</td>
            <td>Designer</td>
            <td className="text-nowrap">+3 434 65 93</td>
          </tr>
        </tbody>
      </Table>

      <Table bordered responsive className="border-primary">
        <thead>
          <tr>
            <th scope="col">#</th>
            <th scope="col">First</th>
            <th scope="col">Last</th>
            <th scope="col">Position</th>
            <th scope="col">Phone</th>
          </tr>
        </thead>
        <tbody>
          <tr>
            <th scope="row">1</th>
            <td>John</td>
            <td>Doe</td>
            <td>CEO, Founder</td>
            <td className="text-nowrap">+3 555 68 70</td>
          </tr>
          <tr>
            <th scope="row">2</th>
            <td>Anna</td>
            <td>Cabana</td>
            <td>Designer</td>
            <td className="text-nowrap">+3 434 65 93</td>
          </tr>
        </tbody>
      </Table>
    </>
  )
}
Top