Applying AdapTable Style

View as Markdown

Summary

  • Format Columns can be given an AdapTable Style
  • Styles can be either always rendered or when a Condition is met
  • An AdapTable Style can set:
    • Colours — text, cell background and border (plus an optional border radius)
    • Font — weight, style, size and decoration
    • Alignment — Left, Right or Center
  • Alternatively a supplied CSS Class can be used

Format Columns in AdapTable can be provided with a Style which is used when the column is rendered.

This style can be one of 2 types:

  • an AdapTable Style object
  • a CSS Style

Hint

Use Conditional Styling when the style should apply only when a particular rule is met

AdapTable Style

Cells styled using Format Column leverage the Adaptable Style.

This will render all Scoped Cells in the Format Column (or those which meet the Condition, if one is set).

AdaptableStyle is composed of CellFontStyle (text), CellBoxStyle (cell chrome) and an optional ClassName:

PropertyTypeDescription
ForeColorstringFont colour in cell: hex, rgb(a) or name
FontWeight'Normal' | 'Bold'Weight of font: Normal or Bold
FontStyle'Normal' | 'Italic'Style of font: Normal or Italic
TextDecoration'None' | 'Underline' | 'Overline' | 'LineThrough'Decoration of font: None, Underline, Overline or LineThrough
FontSize'XSmall' | 'Small' | 'Medium' | 'Large' | 'XLarge'Size of font: XSmall, Small, Medium, Large or XLarge
AlignmentAlignmentAlign to Left, Right or Center
BackColorstringColour background of cell: hex, rgb(a) or name
BorderColorstringColour of cell border: hex, rgb(a) or name
BorderRadiusnumberRounds corners of an element's outer border edge; equivalent of CSS border-radius
ClassNamestringCSS class added to the cell. Colour, font and border properties on this object are still applied.

Hint

All properties are optional — set only those that should differ from the grid default

Find Out More

The Adaptable Style is used in a number of places in AdapTable where styling is required

Colours

You can set the colours for the text, background and (optional) border of the cell.

Style: {
  ForeColor: 'var(--ab-color-palette-21)',
  BackColor: '#2966a8',
  BorderColor: '#80cbc4',
}

Additionally you can set BorderRadius to configure the Border to your requirements.

Style: {
  BorderRadius: 8,
}

Find Out More

See Colour Properties for hex, name, rgb(a) and theme CSS variables

Font

The Font in the Cell is fully stylable via the FontWeight, FontStyle, FontSize and TextDecoration properties.

Note

TextDecoration values are mutually exclusive

Style: {
  FontWeight: 'Bold',
  FontStyle: 'Italic',
  FontSize: 'Large',
  TextDecoration: 'Underline',
}

Alignment

Cell Alignment also lives in AdaptableStyle (i.e. it is not a separate Format Column setting).

Use Left, Right or Center to set the Alignment.

Style: {
  Alignment: 'Center',
}

Hint

Omitting Alignment, or setting Alignment: 'Default', leaves the column / grid default in place

Column Formatting: Column Styles
Fork
  • This example has 3 Format Columns provided which display a Column Style:
    • Name is bold, large and underlined
    • Language has a blue background, yellow text, a rounded teal border and is centre-aligned
    • all Number columns are italic
Loading demo…

CSS Style

It is possible to apply existing CSS styles to the cell instead of defining the styles individually.

Hint

This is done by specifying the property ClassName which references a defined CSS class

Find Out More

See Setting CSS Style for Adaptable Style for more information

Column Formatting: CSS Classes
Fork
  • This demo showcases applying external CSS classes to Format Columns:
    • all numeric columns show the rednumber CSS class
    • the Language and License columns show the bluetext CSS class
Loading demo…

AdapTable Resources