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
}
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'), {
date: 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();
Members
-
rangeObject
-
Current cell range, an object with
fromproperty, withrowandcolproperties (e.q.{from: {row: 1, col: 6}}).
Methods
-
clearRange()
-
Clears the currently selected cell.
-
destroy()
-
Destroys the plugin instance.
-
disablePlugin()
-
Disables the plugin functionality for this Handsontable instance.
-
enablePlugin()
-
Enables the plugin functionality for this Handsontable instance.
-
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(row, column){String|undefined}
-
Gets comment from a cell at the provided coordinates.
Parameters:
Name Type Description rowNumber Visual row index.
columnNumber Visual column index.
Returns: {String|undefined} Returns a content of the comment.
-
getCommentMeta(row, column, property){Mixed}
-
Gets the comment related meta information.
Parameters:
Name Type Description rowNumber Visual row index.
columnNumber Visual column index.
propertyString Cell meta property.
Returns: {Mixed}
-
hide()
-
Hides the comment editor.
-
isEnabled(){Boolean}
-
Checks if the plugin is enabled in the handsontable settings. This method is executed in
Hooks#beforeInit
hook and if it returnstruethan theComments#enablePluginmethod is called.Returns: {Boolean}
-
refreshEditor(force)
-
Refreshes comment editor position and styling.
Parameters:
Name Type Default Description forceBoolean false optional If
truethen recalculation will be forced. -
removeComment(forceRender)
-
Removes a comment from a cell according to previously set range (see
Comments#setRange).Parameters:
Name Type Default Description forceRenderBoolean true optional If set to
true, the table will be re-rendered at the end of the operation. -
removeCommentAtCell(row, column, forceRender)
-
Removes a comment from a specified cell.
Parameters:
Name Type Default Description rowNumber Visual row index.
columnNumber Visual column index.
forceRenderBoolean true optional If
true, the table will be re-rendered at the end of the operation. -
setComment(value)
-
Sets a comment for a cell according to the previously set range (see
Comments#setRange).Parameters:
Name Type Description valueString Comment contents.
-
setCommentAtCell(row, column, value)
-
Sets a comment for a specified cell.
Parameters:
Name Type Description rowNumber Visual row index.
columnNumber Visual column index.
valueString Comment contents.
-
setRange(range)
-
Sets the current cell range to be able to use general methods like
Comments#setComment,Comments#removeComment,Comments#show.Parameters:
Name Type Description rangeObject Object with
fromproperty, each withrowandcolproperties. -
show(){Boolean}
-
Shows the comment editor accordingly to the previously set range (see
Comments#setRange).Returns: {Boolean} Returns
trueif comment editor was shown. -
showAtCell(row, column){Boolean}
-
Shows comment editor according to cell coordinates.
Parameters:
Name Type Description rowNumber Visual row index.
columnNumber Visual column index.
Returns: {Boolean} Returns
trueif comment editor was shown. -
updateCommentMeta(row, column, metaObject)
-
Sets or update the comment-related cell meta.
Parameters:
Name Type Description rowNumber Visual row index.
columnNumber Visual column index.
metaObjectObject Object defining all the comment-related meta information.
-
updatePlugin()
-
Updates the plugin state. This method is executed when
Core#updateSettingsis invoked.