diff --git a/src/controllers/constant.js b/src/controllers/constant.js index 0344cb4..c8ac890 100644 --- a/src/controllers/constant.js +++ b/src/controllers/constant.js @@ -289,6 +289,14 @@ function rightclickHTML(){ dataMenuseparator = false; } + const customsButtons = (config.customs || [{title: 'test'}]).map((item, index) => ` +
+
+ ${item.title} +
+
` + ).join(""); + const rightclickContainer = `
${rightclick.copy}
@@ -423,6 +431,7 @@ function rightclickHTML(){
${toolbar.cellFormat}
+ ${customsButtons}
diff --git a/src/controllers/rowColumnOperation.js b/src/controllers/rowColumnOperation.js index bd5768d..2cbd6e7 100644 --- a/src/controllers/rowColumnOperation.js +++ b/src/controllers/rowColumnOperation.js @@ -1134,6 +1134,29 @@ export function rowColumnOperationInitial(){ }) + + // custom right-click a cell buttton click + $(".luckysheetColsRowsHandleAdd_custom").click(function (clickEvent) { + $("#luckysheet-rightclick-menu").hide(); + const cellRightClickConfig = + luckysheetConfigsetting.cellRightClickConfig; + const rowIndex = Store.luckysheet_select_save[0].row[0]; + const columnIndex = Store.luckysheet_select_save[0].column[0]; + if ( + cellRightClickConfig.customs[ + Number(clickEvent.currentTarget.dataset.index) + ] + ) { + try { + cellRightClickConfig.customs[ + Number(clickEvent.currentTarget.dataset.index) + ].onClick(clickEvent, event, { rowIndex, columnIndex }); + } catch (e) { + console.error("custom click error", e); + } + } + + }); // Add the row up, and click the text area to trigger the confirmation instead of clicking the confirmation button to enhance the experience // $("#luckysheet-addTopRows").click(function (event) { // $("#luckysheetColsRowsHandleAdd_sub .luckysheet-cols-menuitem:first-child").click(function (event) { diff --git a/src/index.html b/src/index.html index 28d3ab6..233bff5 100644 --- a/src/index.html +++ b/src/index.html @@ -1883,6 +1883,14 @@ }, imageClass:"loadingAnimation" } + options.cellRightClickConfig = { + customs: [{ + title: 'test', + onClick: function (clickEvent, event, params) { + console.log('function test click', clickEvent, event, params) + } + }] + } luckysheet.create(options); })