tableHeader: Generate a table header or footer from column names

Description Usage Arguments Value Examples

View source: R/datatables.R

Description

Convenience functions to generate a table header (<thead></thead>) or footer (<tfoot></tfoot>) given the column names. They are basically wrappers of htmltools::tags$th applied to the column names.

Usage

1
2
3
tableHeader(names, escape = TRUE)

tableFooter(names, escape = TRUE)

Arguments

names

a character vector of the column names of the table (if it is an object with column names, its column names will be used instead)

escape

whether to escape the names (see datatable)

Value

A tag object generated by htmltools::tags.

Examples

1
2
3
4
5
6
7
library(DT)
tableHeader(iris)  # or equivalently,
tableHeader(colnames(iris))
tableFooter(iris)  # footer

library(htmltools)
tags$table(tableHeader(iris), tableFooter(iris))

Example output

<thead>
  <tr>
    <th>Sepal.Length</th>
    <th>Sepal.Width</th>
    <th>Petal.Length</th>
    <th>Petal.Width</th>
    <th>Species</th>
  </tr>
</thead>
<thead>
  <tr>
    <th>Sepal.Length</th>
    <th>Sepal.Width</th>
    <th>Petal.Length</th>
    <th>Petal.Width</th>
    <th>Species</th>
  </tr>
</thead>
<tfoot>
  <tr>
    <th>Sepal.Length</th>
    <th>Sepal.Width</th>
    <th>Petal.Length</th>
    <th>Petal.Width</th>
    <th>Species</th>
  </tr>
</tfoot>
<table>
  <thead>
    <tr>
      <th>Sepal.Length</th>
      <th>Sepal.Width</th>
      <th>Petal.Length</th>
      <th>Petal.Width</th>
      <th>Species</th>
    </tr>
  </thead>
  <tfoot>
    <tr>
      <th>Sepal.Length</th>
      <th>Sepal.Width</th>
      <th>Petal.Length</th>
      <th>Petal.Width</th>
      <th>Species</th>
    </tr>
  </tfoot>
</table>

DT documentation built on April 14, 2021, 5:08 p.m.