Skip to content

Description

This plugin allows setting and managing cell comments by either an option in the context menu or with the use of the API.

To enable the plugin, you’ll need to set the comments property of the config object to true:

comments: true

or an object with extra predefined plugin config:

comments: {
displayDelay: 1000,
readOnly: true,
style: {
width: 300,
height: 100
}
}

To add comments at the table initialization, define the comment property in the cell config array as in an example below.

Example

const hot = new Handsontable(document.getElementById('example'), {
data: getData(),
comments: true,
cell: [
{row: 1, col: 1, comment: {value: 'Foo'}},
{row: 2, col: 2, comment: {value: 'Bar'}}
]
});
// Access to the Comments plugin instance:
const commentsPlugin = hot.getPlugin('comments');
// Manage comments programmatically:
commentsPlugin.setCommentAtCell(1, 6, 'Comment contents');
commentsPlugin.showAtCell(1, 6);
commentsPlugin.removeCommentAtCell(1, 6);
// You can also set range once and use proper methods:
commentsPlugin.setRange({from: {row: 1, col: 6}});
commentsPlugin.setComment('Comment contents');
commentsPlugin.show();
commentsPlugin.removeComment();

Options

comments

Source code

comments.comments : boolean | Array<object>

The comments option configures the Comments plugin.

You can set the comments option to one of the following:

SettingDescription
true- Enable the Comments plugin
- Add comment menu items to the context menu
falseDisable the Comments plugin
An object- Enable the Comments plugin
- Add comment menu items to the context menu
- Configure comment settings

If you set the comments option to an object, you can configure the following comment options:

OptionPossible settingsDescription
displayDelayA number (default: 250)Display comments after a delay (in milliseconds)
readOnlytrue | false (default)true: Make comments read-only
styleAn objectSet comment boxes’ width and height (in pixels)

Read more:

Default: false
Example

// enable the `Comments` plugin
comments: true,
// enable the `Comments` plugin
// and configure its settings
comments: {
// display all comments with a 1-second delay
displayDelay: 1000,
// make all comments read-only
readOnly: true,
// set the default size of all comment boxes
style: {
width: 300,
height: 100
}
}

Members

range

Source code

comments.range : object

Current cell range, an object with from property, with row and col properties (e.q. {from: {row: 1, col: 6}}).

Methods

clearRange

Source code

comments.clearRange()

Clears the currently selected cell.

destroy

Source code

comments.destroy()

Destroys the plugin instance.

disablePlugin

Source code

comments.disablePlugin()

Disables the plugin functionality for this Handsontable instance.

enablePlugin

Source code

comments.enablePlugin()

Enables the plugin functionality for this Handsontable instance.

focusEditor

Source code

comments.focusEditor()

Focuses the comments editor element.

getComment

Source code

comments.getComment() ⇒ string | undefined

Gets comment from a cell according to previously set range (see Comments#setRange).

Returns: string | undefined - Returns a content of the comment.

getCommentAtCell

Source code

comments.getCommentAtCell(row, column) ⇒ string | undefined

Gets comment from a cell at the provided coordinates.

ParamTypeDescription
rownumberVisual row index.
columnnumberVisual column index.

Returns: string | undefined - Returns a content of the comment.

getCommentMeta

Source code

comments.getCommentMeta(row, column, property) ⇒ Mixed

Gets the comment related meta information.

ParamTypeDescription
rownumberVisual row index.
columnnumberVisual column index.
propertystringCell meta property.

hide

Source code

comments.hide()

Hides the comment editor.

isEnabled

Source code

comments.isEnabled() ⇒ boolean

Checks if the plugin is enabled in the handsontable settings. This method is executed in Hooks#beforeInit hook and if it returns true then the Comments#enablePlugin method is called.

refreshEditor

Source code

comments.refreshEditor([force])

Refreshes comment editor position and styling.

ParamTypeDefaultDescription
[force]booleanfalseoptional If true then recalculation will be forced.

removeComment

Source code

comments.removeComment([forceRender])

Removes a comment from a cell according to previously set range (see Comments#setRange).

ParamTypeDefaultDescription
[forceRender]booleantrueoptional If set to true, the table will be re-rendered at the end of the operation.

removeCommentAtCell

Source code

comments.removeCommentAtCell(row, column, [forceRender])

Removes a comment from a specified cell.

ParamTypeDefaultDescription
rownumberVisual row index.
columnnumberVisual column index.
[forceRender]booleantrueoptional If true, the table will be re-rendered at the end of the operation.

setComment

Source code

comments.setComment(value)

Sets a comment for a cell according to the previously set range (see Comments#setRange).

ParamTypeDescription
valuestringComment contents.

setCommentAtCell

Source code

comments.setCommentAtCell(row, column, value)

Sets a comment for a specified cell.

ParamTypeDescription
rownumberVisual row index.
columnnumberVisual column index.
valuestringComment contents.

setRange

Source code

comments.setRange(range)

Sets the current cell range to be able to use general methods like Comments#setComment, Comments#removeComment, Comments#show.

ParamTypeDescription
rangeobjectObject with from property, each with row and col properties.

show

Source code

comments.show() ⇒ boolean

Shows the comment editor accordingly to the previously set range (see Comments#setRange).

Returns: boolean - Returns true if comment editor was shown.

showAtCell

Source code

comments.showAtCell(row, column) ⇒ boolean

Shows comment editor according to cell coordinates.

ParamTypeDescription
rownumberVisual row index.
columnnumberVisual column index.

Returns: boolean - Returns true if comment editor was shown.

updateCommentMeta

Source code

comments.updateCommentMeta(row, column, metaObject)

Sets or update the comment-related cell meta.

ParamTypeDescription
rownumberVisual row index.
columnnumberVisual column index.
metaObjectobjectObject defining all the comment-related meta information.

updatePlugin

Source code

comments.updatePlugin()

Updates the plugin’s state.

This method is executed when updateSettings() is invoked with any of the following configuration options: