Skip to content

Commit

Permalink
change hot_row function to accommodate multiple rows (#258)
Browse files Browse the repository at this point in the history
* Change hot_row to accommodate multiple rows

* fix spaces

* Update documentation for hot_row

Update hot_row row parameter to include the use of a vector to specify the rows to apply to. Also, altered the descriptions of hot_row and hot_rows to point out the difference between these functions since hot_row now accepts multiple rows.

* Use multiple rows in read-only example

I put a vector of rows into the hot_row() function call of the read-only section to show the capability to set multiple rows at once.

Fixes #255 and #234
  • Loading branch information
Paul-A-Kavan authored and jrowen committed Jul 21, 2018
1 parent 96aced7 commit a89ffed
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
29 changes: 16 additions & 13 deletions R/rhandsontable.R
Expand Up @@ -478,7 +478,8 @@ hot_col = function(hot, col, type = NULL, format = NULL, source = NULL,

#' Handsontable widget
#'
#' Configure rows. See
#' Configure row settings that pertain to the entire table.
#' Note that hot_rows is not to be confused with \code{\link{hot_row}}. See
#' \href{http://handsontable.com}{Handsontable.js} for details.
#'
#' @param hot rhandsontable object
Expand All @@ -503,29 +504,31 @@ hot_rows = function(hot, rowHeights = NULL, fixedRowsTop = NULL) {

#' Handsontable widget
#'
#' Configure a row. See
#' Configure properties of all cells in a given row(s).
#' Note that hot_row is not to be confused with \code{\link{hot_rows}}. See
#' \href{http://handsontable.com}{Handsontable.js} for details.
#'
#' @param hot rhandsontable object
#' @param row numeric row index
#' @param readOnly logical making the row read-only
#' @param row numeric vector of row indexes
#' @param readOnly logical making the row(s) read-only
#' @examples
#' library(rhandsontable)
#' MAT = matrix(rnorm(50), nrow = 10, dimnames = list(LETTERS[1:10],
#' letters[1:5]))
#'
#' rhandsontable(MAT, width = 300, height = 150) %>%
#' hot_row(1, readOnly = TRUE)
#' @seealso \code{\link{hot_cols}}, \code{\link{hot_cell}}
#' hot_row(c(1,3:5), readOnly = TRUE)
#' @seealso \code{\link{hot_cols}}, \code{\link{hot_cell}}, \code{\link{hot_rows}}
#' @export
hot_row = function(hot, row, readOnly = NULL) {
ct = hot$x$rDataDim[2]
for (i in seq_len(ct)) {
if (!is.null(readOnly)) {
hot = hot %>% hot_cell(row, i, readOnly = readOnly)
}
}

if ( !is.null(readOnly) ) {
colDim = hot$x$rDataDim[2]
for ( i in row ) {
for ( j in seq_len(colDim) ) {
hot = hot %>% hot_cell(i, j, readOnly = readOnly)
}
}
}
hot
}

Expand Down
2 changes: 1 addition & 1 deletion docs/index.Rmd
Expand Up @@ -386,7 +386,7 @@ DF = data.frame(val = 1:10, bool = TRUE, big = LETTERS[1:10],
rhandsontable(DF, width = 550, height = 300) %>%
hot_col("val", readOnly = TRUE) %>%
hot_row(4, readOnly = TRUE) %>%
hot_row(c(4,6,10), readOnly = TRUE) %>%
hot_cell(7, "dt", readOnly = TRUE)
```

Expand Down

0 comments on commit a89ffed

Please sign in to comment.