Making part of the table read-only
I was wondering if there was a way to make part of an excelTable read-only (e.g. a cell, several specific cells, a row, a column...). The excelTable() function has the editable argument, which makes the entire table editable or not.
Thank you
It is possible with updateTable.
updateTable <- "function(instance, td, col, row, value, label, cellName) {
var header = instance.jexcel.getHeader (col);
if (header == 'Your header name') {
td.classList.add ('readonly') ;
}
}
excelTable(
data = df,
updateTable = htmlwidgets::JS(updateTable)
)
Okay, so you need to do it with JavaScript. I'll try it out then close the comment once it works. Thank you so much!
@gueyenono Thanks you for the question. This could be a functionality that we could add it the future releases. I'll label this as a feature request.
@daeyoonlee is it possible to freeze (readonly), 2 or more variables ? Thanks
@daeyoonlee is it possible to freeze (readonly), 2 or more variables ? Thanks
I'm not really comfortable with JS, but this work.
updateTable = "function(instance, td, col, row, value, label, cellName) {
var header = instance.jexcel.getHeader(col);
if (header != 'Availability') {
td.classList.add('readonly') ;
}
}"
data = data.frame(Model = c('Mazda', 'Pegeout', 'Honda Fit', 'Honda CRV'),
Date=c('2006-01-01', '2005-01-01','2004-01-01', '2003-01-01' ),
Availability = c(TRUE, FALSE, TRUE, TRUE))
columns = data.frame(title=c('Model', 'Date', 'Availability'),
width= c(500, 500, 300),
type=c('text', 'calendar', 'checkbox'))
excelTable(data=data, columns = columns, updateTable = htmlwidgets::JS(updateTable))
@mostafa790 works well, but then you get the greyed out look, not very readable. I have a situation of two reference columns and one column to be edited based on the values in the reference columns.
@mostafa790 hello I change your code into
my_col=c("Model","Date")
updateTable = "function(instance, td, col, row, value, label, cellName) {
var header = instance.jexcel.getHeader(col);
if (header %in% my_col) {
td.classList.add('readonly') ;
}
}"
But this doesn't seem work. I'm don't know anything about JS. Can you fix this?
hello @zhangjunjiang , Sorry for my late message.
You cant combine R and JS code, try to remplace header %in% my_col by !(header in my_col)
Good luck :)
Hi
Thanks to @Swechhya for publishing this package and for all users who responded to this thread. @mostafa790 provided a workaround for rendering columns read-only. I was wondering if there was a similar mechanisms for rendering rows read-only.
More specifically, is there a way to make rows stored in reactive variables read only?
Thanks in advance