Posted 27 March 2023, 3:29 pm EST
Hello,
I would like to know if it is possible to perform the DragDropBlock event with the protected sheet?
Forums Home / Spread / SpreadJS
Posted by: pedro.moraes on 27 March 2023, 3:29 pm EST
Posted 27 March 2023, 3:29 pm EST
Hello,
I would like to know if it is possible to perform the DragDropBlock event with the protected sheet?
Posted 28 March 2023, 7:46 am EST
Hello,
It is not possible to allow drag drop on a protected sheet. However, you can allow drag insert rows and drag insert columns when the sheet is protected. You can do so by setting the “allowDragInsertRows” and “allowDragInsertColumns” property of IProtectionOptions interface to true in sheet.options.protectionOptions property of sheet(worksheet). The drag insert row and drag insert column action is performed by dragging a selection while pressing the “Shift” key.
Please refer to the code snippet which explains the same.
sheet.options.isProtected = true;
sheet.options.protectionOptions.allowDragInsertRows = true;
sheet.options.protectionOptions.allowDragInsertColumns = true;
Doc references:
sheet.options.protectionOptions: https://www.grapecity.com/spreadjs/api/v16/interfaces/GC.Spread.Sheets.IProtectionOptions#interface-iprotectionoptions
IProtectionOptions.allowDragInsertRows: https://www.grapecity.com/spreadjs/api/v16/interfaces/GC.Spread.Sheets.IProtectionOptions#allowdraginsertrows
IProtectionOptions.allowDragInsertColumns:https://www.grapecity.com/spreadjs/api/v16/interfaces/GC.Spread.Sheets.IProtectionOptions#allowdraginsertcolumns
regards,
Avinash
Posted 28 March 2023, 2:09 pm EST
Is it possible for me not to protect the sheet and block the cell for editing?
Posted 29 March 2023, 2:00 am EST
Hello,
You can block a cell range from being edited without protecting the sheet. You can do this by binding an event handler to GC.Spread.Sheets.Events.EditStarting event using sheet.bind() method. In the handler, you can check if a cell is inside a particular cell range and accordingly cancel the EditStarting event to prevent the cell editor from opening.
Please refer to the code snippet and attached sample which explains the same.
sheet.getRange(1, 1, 2, 2).backColor(‘lightgrey’);
sheet.bind(GC.Spread.Sheets.Events.EditStarting, (event, args) => {
let range = new GC.Spread.Sheets.Range(1, 1, 2, 2);
let activeCellRange = new GC.Spread.Sheets.Range(args.row, args.col, 1, 1);
if (range.containsRange(activeCellRange)) {
args.cancel = true;
}
});
Sample: https://jscodemine.grapecity.com/share/cN43102L-kO_G2evKIFqkQ/?defaultOpen={"OpenedFileName"%3A["%2Findex.html"%2C"%2Fsrc%2Fapp.js"]%2C"ActiveFile"%3A"%2Fsrc%2Fapp.js"}
Please let us know if you face any issues.
Doc reference
sheet.bind():https://www.grapecity.com/spreadjs/api/v15/classes/GC.Spread.Sheets.Worksheet#bind
GC.Spread.Sheets.Events.EditStarting event: https://www.grapecity.com/spreadjs/api/classes/GC.Spread.Sheets.Events#editstarting
regards,
Avinash