# Comments Technical Reference

Canonical page: https://www.adaptabletools.com/docs/technical-reference-comments

## Comment State

| Property | Type | Description |
| --- | --- | --- |
| [CommentThreads](https://www.adaptabletools.com/docs/reference/commentstate.md#commentthreads) | [`CommentThread`](https://www.adaptabletools.com/docs/reference/commentthread.md)`[]` | Comment threads for this session. Each thread belongs to one cell (`PrimaryKeyValue` and `ColumnId`) and holds its `Comments` in order. |

### CommentThread

| Property | Type | Description |
| --- | --- | --- |
| [Comments](https://www.adaptabletools.com/docs/reference/commentthread.md#comments) | [`AdaptableComment`](https://www.adaptabletools.com/docs/reference/adaptablecomment.md)`[]` | Collection of Comments for this Cell |
| [Uuid](https://www.adaptabletools.com/docs/reference/commentthread.md#uuid) | `TypeUuid` | Unique identifier for Comment |

### Adaptable Comment

| Property | Type | Description |
| --- | --- | --- |
| [AdaptableId](https://www.adaptabletools.com/docs/reference/adaptablecomment.md#adaptableid) | `string` | Id of this AdapTable instance |
| [Author](https://www.adaptabletools.com/docs/reference/adaptablecomment.md#author) | `\{ UserName: string; \}` | Author of the Comment |
| [Timestamp](https://www.adaptabletools.com/docs/reference/adaptablecomment.md#timestamp) | `number` | When Comment was made |
| [Uuid](https://www.adaptabletools.com/docs/reference/adaptablecomment.md#uuid) | `TypeUuid` | Unique identifier for the Comment |
| [Value](https://www.adaptabletools.com/docs/reference/adaptablecomment.md#value) | `string` | Content of the Comment |

-------------

## Comment Options

| Property | Type | Description | Default |
| --- | --- | --- | --- |
| [dateFormat](https://www.adaptabletools.com/docs/reference/commentoptions.md#dateformat) | `string \| (() => string)` | Date Format string for Comments timestamp | &#39;dd-MM-yyyy HH:mm:ss&#39; |
| [isCellCommentable](https://www.adaptabletools.com/docs/reference/commentoptions.md#iscellcommentable) | `(commentableCellContext: `[`CommentableCellContext`](https://www.adaptabletools.com/docs/reference/commentablecellcontext.md)`) => boolean` | Function to configure if a cell can contain Comments |   |
| [showCommentAction](https://www.adaptabletools.com/docs/reference/commentoptions.md#showcommentaction) | `'hover' \| 'menu'` | Whether to show Comments by hovering (default) or via context menu | &#39;hover&#39; |
| [showPopupCloseButton](https://www.adaptabletools.com/docs/reference/commentoptions.md#showpopupclosebutton) | `boolean` | Show the Close Button in the Comments Popup | true |

`isCellCommentable` receives a [`CommentableCellContext`](https://www.adaptabletools.com/docs/reference/commentablecellcontext.md):

| Property | Type | Description |
| --- | --- | --- |
| [gridCell](https://www.adaptabletools.com/docs/reference/commentablecellcontext.md#gridcell) | [`GridCell`](https://www.adaptabletools.com/docs/reference/gridcell.md) | Grid Cell in AdapTable which has been clicked |
| [adaptableContext](https://www.adaptabletools.com/docs/reference/commentablecellcontext.md#adaptablecontext) | `any` | Custom application Context provided in `AdaptableOptions.adaptableContext` |

### Loading and Saving Comments

Comment Options contains 2 functions which developers must provide in order to load and save Comments:

| Method | Returns | Description |
| --- | --- | --- |
| [loadCommentThreads(commentLoadContext)](https://www.adaptabletools.com/docs/reference/commentoptions.md#loadcommentthreads) | `Promise<`[`CommentThread`](https://www.adaptabletools.com/docs/reference/commentthread.md)`[]>` | Loads every comment thread when the grid starts. |
| [persistCommentThreads(commentThreads)](https://www.adaptabletools.com/docs/reference/commentoptions.md#persistcommentthreads) | `Promise<void>` | Saves the threads after a comment is added, edited or deleted.<br/><br/>Called with the full set, not only the thread that changed. |

-------------

## Comment API

| Method | Returns | Description |
| --- | --- | --- |
| [addComment(commentText, cellAddress)](https://www.adaptabletools.com/docs/reference/commentapi.md#addcomment) | `void` | Add a Comment to a Comment Thread |
| [addCommentThread(commentThread)](https://www.adaptabletools.com/docs/reference/commentapi.md#addcommentthread) | `void` | Create a new Comment Thread |
| [clearComments()](https://www.adaptabletools.com/docs/reference/commentapi.md#clearcomments) | `void` | Clear all Comment Threads in the grid |
| [deleteComment(comment, cellAddress)](https://www.adaptabletools.com/docs/reference/commentapi.md#deletecomment) | `void` | Delete a Comment |
| [deleteCommentThread(cellAddress)](https://www.adaptabletools.com/docs/reference/commentapi.md#deletecommentthread) | `void` | Delete all Comments for a particular cell |
| [editComment(comment, cellAddress)](https://www.adaptabletools.com/docs/reference/commentapi.md#editcomment) | `void` | Edit a Comment |
| [getAllComments()](https://www.adaptabletools.com/docs/reference/commentapi.md#getallcomments) | [`CommentThread`](https://www.adaptabletools.com/docs/reference/commentthread.md)`[]` | Return all Comment Threads in the grid |
| [getCommentThreadForCell(cellAddress)](https://www.adaptabletools.com/docs/reference/commentapi.md#getcommentthreadforcell) | [`CommentThread`](https://www.adaptabletools.com/docs/reference/commentthread.md)` \| undefined` | Return the Comment Thread for a particular cell |
| [hideCommentsPopup()](https://www.adaptabletools.com/docs/reference/commentapi.md#hidecommentspopup) | `void` | Close the Comment Popup |
| [setComments(commentThreads)](https://www.adaptabletools.com/docs/reference/commentapi.md#setcomments) | `void` | Sets the Comment Threads in the grid |

-------------

## Comment Changed Event

The Comment Changed Event fires whenever a Comment changes.

### CommentChangedInfo

The event comprises a single [`CommentChangedInfo`](https://www.adaptabletools.com/docs/reference/commentchangedinfo.md) object which provides all the current Comment Threads.

| Property | Type | Description |
| --- | --- | --- |
| [commentThreads](https://www.adaptabletools.com/docs/reference/commentchangedinfo.md#commentthreads) | [`CommentThread`](https://www.adaptabletools.com/docs/reference/commentthread.md)`[]` | Every comment thread after the change.<br/><br/>This is the full list `commentApi.getAllComments()` returns, not only the thread that changed. |
| [adaptableContext](https://www.adaptabletools.com/docs/reference/commentchangedinfo.md#adaptablecontext) | `any` | Custom application Context provided in `AdaptableOptions.adaptableContext` |

### Event Subscription

Subscribing to the Event is done the same way as with all [Adaptable Events](https://www.adaptabletools.com/docs/technical-reference-adaptable-events/index.md):

```ts
api.eventApi.on('CommentChanged', (eventInfo: CommentChangedInfo) => {
    // do something with the info
});
```
