@quantlab/handsontable
Version:
Spreadsheet-like data grid editor that provides copy/paste functionality compatible with Excel/Google Docs
32 lines (26 loc) • 933 B
JavaScript
import {checkSelectionConsistency, markLabelAsSelected} from './../utils';
export const KEY = 'make_read_only';
export default function readOnlyItem() {
return {
key: KEY,
name() {
let label = 'Read only';
let atLeastOneReadOnly = checkSelectionConsistency(this.getSelectedRange(), (row, col) => this.getCellMeta(row, col).readOnly);
if (atLeastOneReadOnly) {
label = markLabelAsSelected(label);
}
return label;
},
callback() {
let range = this.getSelectedRange();
let atLeastOneReadOnly = checkSelectionConsistency(range, (row, col) => this.getCellMeta(row, col).readOnly);
range.forAll((row, col) => {
this.setCellMeta(row, col, 'readOnly', !atLeastOneReadOnly);
});
this.render();
},
disabled() {
return !(this.getSelectedRange() && !this.selection.selectedHeader.corner);
}
};
}