javascriptrhandsontablerhandsontable

rhandsontable column sorting to have NAs on top


how do you make NAs appear on top when column sorting a rhandsontable. NA values always end up at the bottom during the sorting.

mtcars[1, ] <- NA
rhandsontable(mtcars) %>% 
  hot_cols(columnSorting = TRUE)

enter image description here enter image description here


Solution

  • After a look at the docs the best I could come up with is to set sortEmptyCells = TRUE which will still put NAs at the bottom when sorting in descending order, but vice versa will put them on the top when sorting in ascending order.

    library(rhandsontable)
    
    mtcars[1, ] <- NA
    
    rhandsontable(mtcars[1:10, 1:2]) %>%
      hot_cols(
        columnSorting = list(
          sortEmptyCells = TRUE
        )
      )
    

    enter image description here