Hi friends,
I am reaching out to inquire about the note functionality within the Spreadsheet JS component.
I would like to know if there is a way to programmatically delete a note from a specific cell, using either the cell's address (such as 'A1') or the cell indices (for example, { row: 0, col: 0 }).
This capability would be highly beneficial for dynamic note management, particularly in scenarios where users add a note but do not enter any content, resulting in the red note symbol remaining visible even though the note is empty.
I would appreciate any information you can provide regarding whether this functionality is available, or any way to do it.
Thank you for your attention, and I look forward to your prompt response.
Hi Tomas De arco,
We have validated your reported requirement, and unfortunately, we would like
to inform you that currently, we don't have a direct option to remove notes
from a specific cell in our spreadsheet. However, you can achieve your
requirement with a workaround at the sample level.
If the notes property of the cell is empty during initial rendering, you can
prevent adding the red indicator to the cell with empty notes by assigning null to the notes
property of args.cell
in the beforeCellRender
event, as shown in the shared code snippet below.
Additionally, while adding notes with an empty value via UI action, you can
remove the red indicator element from the cell in our actionComplete
event using the shared code snippet below.
For your reference, we
have provided a sample below. In this example, we have fulfilled your
requirement for cell 'B5'. If you add empty notes to cell 'B5', the red
indicator will be removed, as per your request
Sample: https://stackblitz.com/edit/ammrx2-cqvekj?file=index.ts
CODE SNIPPET:
|
// You can add your condition here for the required cell. if ((args.address === 'B5') && args.cell && args.cell.notes === '') { args.cell.notes = null; // To remove the note element from the cell during initial rendering } }, actionComplete: function (args) { if (args.action === 'addNote' && args.eventArgs && args.eventArgs.notes === '') { //To confirm the note's value is empty. let cellAddress: string = args.eventArgs.address.split('!')[1]; if (cellAddress === 'B5') { // You can add your condition here for the required cell. let cellIndexes: number[] = getCellIndexes(cellAddress); let rowIdx: number = cellIndexes[0]; let colIdx: number = cellIndexes[1]; let cell: CellModel = getCell(rowIdx, colIdx, spreadsheet.getActiveSheet()); cell.notes = null; // Assigned the note property value as null to prevent adding the note element in future actions. let cellEle: HTMLElement = spreadsheet.getCell(rowIdx, colIdx); let noteEle: HTMLElement = cellEle.querySelector('.e-addNoteIndicator'); if (noteEle) { cellEle.removeChild(noteEle); // Removed the added note element from the cell element. } } } } |
Kindly check the details shared above on your end and get back to us if you
need further clarifications regarding this.
To delete a note from a specific cell programmatically or automatically if it is empty, you can use the ClearContents method in Google Apps Script. Here's an example of how you can achieve this:
javascriptfunction deleteNoteIfEmpty() { var sheet = SpreadsheetApp.getActiveSheet(); var cell = sheet.getRange("A1"); // Replace "A1" with the desired cell reference if (cell.getNotes() === "") { cell.clearNotes(); } }
Here's how the code works:
getActiveSheet() method is used to get the currently active sheet in the Google Spreadsheet.getRange() method is used to specify the cell reference from which you want to delete the note. In this example, it's set to "A1", but you can replace it with the desired cell reference.getNotes() method is used to retrieve the note content of the specified cell. If the note is empty, it will return an empty string.if statement checks if the note content is an empty string. If it is, the clearNotes() method is called to delete the note from the cell.To run this script, you can follow these steps:
Note: If you want to run the script manually, you can click on the "Run" button in the script editor or create a custom menu item that triggers the script.Remember to replace "A1" with the desired cell reference where you want to delete the note if it is empty.
Temu, an online shopping platform, is offering significant discounts through two prominent coupon codes: ACT200019 and ACP856709.
Download the Temu app, available for both iPhone and Android devices.
Browse through the wide range of products available on the platform.
Add desired items to your cart.
During the checkout process, enter either ACT200019 or ACP856709 in the coupon code field.
Apply the code to see the discount reflected in your total.
Thank you so much @Janakiraman Sakthivel
Hi Tomas,
We're glad your issue was resolved. Please get back to us for further assistance in the future.
Regards,
Florence L.