Posted 27 May 2021, 7:17 pm EST
Hi,
For this, you need to use the Selection Changed and toggle the custom State according. Please refer to the following code snippet that disables the custom button and custom context menu item when the active cell has the Sum formula.
spread.bind('SelectionChanged', (e, args) => {
let sheet = args.sheet;
let activeCell = sheet.getCell(
sheet.getActiveRowIndex(),
sheet.getActiveColumnIndex()
);
let formula = activeCell.formula();
console.log(formula);
if (formula && formula.indexOf('SUM') != -1) {
designer.setData('myState', false);
} else {
designer.setData('myState', true);
}
});
//set the formulas on sheet
spread
.getActiveSheet()
.getRange('B4:G4')
.formula('SUM(5,4,5,6)');
sample: https://stackblitz.com/edit/js-iubtxw?file=index.js
Regards,
Avinash