通过配置enableContext设置禁用与否,会有点bug,点击不同单元格,有时候设置会不生效
- window.onload = function () {
- const designerConfig = JSON.parse(JSON.stringify(GC.Spread.Sheets.Designer.DefaultConfig));
- designerConfig.ribbon[0].buttonGroups = [
- {
- label: "test",
- commandGroup: {
- children: [
- {
- direction: "vertical",
- commands: ["myTest"],
- },
- ],
- }
- }
- ]
- designerConfig.commandMap = {
- myTest: {
- text: "myTest",
- bigButton: true,
- commandName: "myTest",
- enableContext: '!cusTest',
- iconClass: 'ribbon-button-barcode'
- }
- };
- const designer = new GC.Spread.Sheets.Designer.Designer(document.getElementById("designer"), designerConfig);
- const spread = designer.getWorkbook();
- const sheet = spread.getActiveSheet();
- let count = 0;
- for(let i = 0; i<6; i++){
- for(let j = 0; j<6; j++){
- count++;
- sheet.getCell(i,j).value(count);
- }
- }
- spread.bind(GC.Spread.Sheets.Events.SelectionChanged, ()=>{
- const range = sheet.getSelections()[0];
- const val = sheet.getCell(range.row, range.col).value();
- designer.setData('cusTest', val % 2 == 0);
- })
- }
复制代码 |