Styling Editable, Read-Only & Edited Cells

View as Markdown

Summary

  • AdapTable allows developers to specify which cells in AG Grid are editable or read-only
  • Use userInterfaceOptions — editableCellStyle, readOnlyCellStyle, editedCellStyle — each an Adaptable Style object

Topics on this Page

TopicSummary
Editable cellseditableCellStyle
Read-only cellsreadOnlyCellStyle
Edited cellseditedCellStyle and demos

You might wish to visually indicate to your users which Cells in AG Grid are editable or read-only.

This is particularly the case if editability is set at the Grid Cell, rather than Column, level.

Find Out More

Additionally you might want to show which cells have been edited (with an option to undo the edit).

Styling can be provided via 3 parallel functions in User Interface Options:

Hint

Typically users will provide one, but not both, of the first 2 functions

  • editableCellStyle sets the style for editable cells
  • readOnlyCellStyle sets the style for readonly cells
  • editedCellStyle sets the style for edited cells

All 3 functions use the commonly used Adaptable Style object which can style a Cell in many ways.

Styling Editable Cells

Use the editableCellStyle property to set a Style for all editable Cells in the Grid.

editableCellStyle

Adaptable Style to apply to Editable Cells
Styling Editable Cells
Fork
  • In this example we provide an editableCellStyle (in User Interface Options) of a yellow border with a radius so that editable cells to be readily identified
  • We also provide 3 Editable cell Rules - set using isCellEditable property in Edit Options:
    • All cells in a row where Language cell value is HTML are editable
    • GitHub Watchers is editable for cells with a value over 1,000
    • Issue Change is always editable

Expand to see the Adaptable Options code

Loading demo…

Styling Read-Only Cells

Use the readOnlyCellStyle property to set a Style for all read-ony Cells in the Grid.

Deep Dive

How AdapTable asseses whether a Cell is Read-Only

readOnlyCellStyle

Adaptable Style to apply to Read Only Cells
Styling Read-Only Cells
Fork
  • In this example we provide a readOnlyCellStyle (in User Interface Options) of a gray background so that read-only cells can be readily identified
  • We provide 3 Read-only cell Rules - set using isCellEditable property in Edit Options (same as in above example but inverted):
    • All cells in a row where Language cell value is HTML are read-only
    • GitHub Watchers is read-only for cells with a value over 1,000
    • Issue Change is always read-only

Expand to see the Adaptable Options code

Loading demo…

Styling Edited Cells

Use the editedCellStyle property to set a Style for all Cells in the Grid which have been edited.

Hint

AdapTable leverages Data Change History to monitor which Cells have been edited, so ensure that is turned on

editedCellStyle

Adaptable Style to apply to Edited Cells
Styling Edited Cells
Fork
  • In this example we provide a editedCellStyle (in User Interface Options) of a gray background so that edited cells can be readily identified
  • We set Data Change History to be active by default and programmatically edit 2 cells in the Language column

Expand to see the code used

Loading demo…

Find Out More

The 'Undoing Data Edits' Blog Post illustrates adding a custom Context Menu Item to edited cells to undo the edit

FAQ

Editable vs read-only styling together? Typically provide one of editableCellStyle or readOnlyCellStyle, not both — use whichever matches how you define editability (see Setting Cell Editability).

Do styles use theme variables? Yes — e.g. var(--ab-color-palette-16) in the edited-cell demo; see Referencing Theme Variables.