getting started

library(handsontable)

basic

handsontable(data = iris[1:10, ], adaptiveHeight = TRUE)

read-only

to make the table read-only, set readOnly = TRUE. this will prevent any editing of the table.

handsontable(
  data = iris[1:5, ],
  adaptiveHeight = TRUE,
  readOnly = TRUE
)

headers

  • colHeaders

    by default, colHeaders = TRUE and uses the column names of the data frame.

    handsontable(
      data = iris[1:5, ],
      adaptiveHeight = TRUE,
      colHeaders = TRUE
    )

    setting colHeaders = FALSE will remove the column headers.

    handsontable(
      data = iris[1:5, ],
      adaptiveHeight = TRUE,
      colHeaders = FALSE
    )

    to set custom column headers, pass a character vector to colHeaders.

    handsontable(
      data = iris[1:5, ],
      adaptiveHeight = TRUE,
      colHeaders = c(
        "Sepal Length",
        "Sepal Width",
        "Petal Length",
        "Petal Width",
        "Species"
      )
    )
  • rowHeaders

    by default, rowHeaders = TRUE and uses the row names of the data frame.

    handsontable(
      data = mtcars[1:5, ],
      adaptiveHeight = TRUE,
      rowHeaders = TRUE,
      rowHeaderWidth = 200
    )

    setting rowHeaders = FALSE will remove the row headers.

    handsontable(
      data = mtcars[1:5, ],
      adaptiveHeight = TRUE,
      rowHeaders = FALSE
    )

    to set custom row headers, pass a character vector to rowHeaders.

    handsontable(
      data = mtcars[1:5, ],
      adaptiveHeight = TRUE,
      rowHeaders = c("Row 1", "Row 2", "Row 3", "Row 4", "Row 5")
    )

dimensions

  • width & height

    handsontable(
      data = mtcars,
      width = 500,
      height = 300,
      rowHeaderWidth = 200
    )
  • setting adaptiveHeight = TRUE will make the table height adapt to the content of the cells, so that no vertical scrollbar is shown.

    handsontable(
      data = mtcars,
      adaptiveHeight = TRUE,
      rowHeaderWidth = 200
    )

column widths

to set the width of individual columns, pass a numeric vector to colWidths.

handsontable(
  data = iris[1:5, ],
  adaptiveHeight = TRUE,
  colWidths = c(100, 150, 200, 250, 300)
)

column stretching

  • stretchH = "all" will stretch all columns to fit the width of the table.

    handsontable(
      data = iris[1:5, 1:3],
      adaptiveHeight = TRUE,
      stretchH = "all"
    )
  • stretchH = "last" will stretch the last column to fit the width of the table.

    handsontable(
      data = iris[1:5, 1:3],
      adaptiveHeight = TRUE,
      stretchH = "last"
    )
  • stretchH = "none" will not stretch any columns.

    handsontable(
      data = iris[1:5, 1:3],
      adaptiveHeight = TRUE,
      stretchH = "none"
    )

fixed columns & rows

  • set fixedColumnsLeft to fix a number of columns on the left side of the table.

    handsontable(
      data = mtcars[1:10, ],
      adaptiveHeight = TRUE,
      fixedColumnsLeft = 2,
      rowHeaderWidth = 200,
      width = 500
    )
  • set fixedRowsTop to fix a number of rows on the top of the table.

    handsontable(
      data = mtcars,
      fixedRowsTop = 2,
      rowHeaderWidth = 200
    )
  • set fixedRowsBottom to fix a number of rows on the bottom of the table.

    handsontable(
      data = mtcars,
      fixedRowsBottom = 2,
      rowHeaderWidth = 200
    )

manual column & row move

  • setting manualColumnMove = TRUE will allow users to move columns by dragging the column headers.

    handsontable(
      data = iris[1:10, ],
      adaptiveHeight = TRUE,
      manualColumnMove = TRUE
    )
  • setting manualRowMove = TRUE will allow users to move rows by dragging the row headers.

    handsontable(
      data = mtcars,
      adaptiveHeight = TRUE,
      manualRowMove = TRUE,
      rowHeaderWidth = 200
    )