How to provide copy-paste and autofill options for cell template elements in ASP.NET Core Spreadsheet?
This article explains how to provide copy-paste and autofill options for cell template elements in ASP.NET Core Spreadsheet.
In a button-click event, create the input element inside the spreadsheet cell element and render the template (ej2.dropdowns.ComboBox) into it. In the actionComplete event, fetch the range of the selected cells and update the template to the same.
[CSHTML]
<button id="addTemplateBtn" class="e-btn"> Add Template </button> <ejs-spreadsheet id="spreadsheet" actionComplete="actionComplete"> </ejs-spreadsheet> <script> document.getElementById("addTemplateBtn").addEventListener('click', addTemplate); // Binding the method with a button to add template. function actionComplete(args) { var cellIdx = []; // Checking whether the action is clipboard event or autofill. if (args.action == 'clipboard' || args.action == 'autofill') { var actionRange = args.eventArgs.pastedRange ? args.eventArgs.pastedRange : args.eventArgs.fillRange; // Assigning range according to the action. // Splitting the range fetched to get the address. var address = actionRange.indexOf('!') > -1 ? actionRange.split('!')[1] : actionRange; // Fetch the index value of the address. cellIdx = ejs.spreadsheet.getRangeIndexes(address); // Iterating between the range to update the template. for (var rowIdx = cellIdx[0]; rowIdx <= cellIdx[2]; rowIdx++) { for (var colIdx = cellIdx[1]; colIdx <= cellIdx[3]; colIdx++) { addTemplate(rowIdx, colIdx); } } } } // Function to add template to the current cell or selected range. function addTemplate(row, col) { var spreadsheetObj = ej.base.getComponent(document.getElementById('spreadsheet'), 'spreadsheet'); var sheet = spreadsheetObj.getActiveSheet(); var activeCell = sheet.activeCell; var cellObj = ejs.spreadsheet.getCellIndexes(activeCell); var sportsData = ['Badminton', 'Basketball', 'Cricket', 'Football', 'Golf', 'Gymnastics', 'Hockey', 'Tennis']; // Initializing the data to be append into the combobox. // Condition to check whether the column value is present or not. var cell = col ? spreadsheetObj.getCell(row, col) : spreadsheetObj.getCell(cellObj[0], cellObj[1]); // Creating an input element to append the template into it. var inputEle = document.createElement("input") // Append the template (combo box) for the range selected / for the cell selected. cell.appendChild(inputEle) new ej.dropdowns.ComboBox({ placeholder: 'Select Parameter', dataSource: sportsData, autofill: true, popupHeight: '220px', value: "Football" }, cell.childNodes[1]) // Update the template to the cell or range. spreadsheetObj.updateCell({ value: '' }, activeCell); var height = col ? row : cellObj[0]; // Update the height as per the template height. spreadsheetObj.setRowHeight(40, height, sheet.id); } </script>
Sample Link: https://www.syncfusion.com/downloads/support/directtrac/general/ze/Template-CopyPaste-Autofill-1984957760
Output
I hope you enjoyed learning about how to provide copy-paste and autofill options for cell template elements in ASP .NET Core Spreadsheet.
You can refer to our ASP.NET Core Spreadsheet’s feature tour page to know about its other groundbreaking feature representations. You can also explore our ASP.NET Core Spreadsheet documentation to understand how to present and manipulate data.
For current customers, you can check out our WinForms components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our ASP.NET Core Spreadsheet and other ASP.NET Core components.
If you have any queries or require clarifications, please let us know in comments below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!