Badge Style
Summary
- Badge Style decorates each cell value with one or more styled "pills" (labels)
- Each pill is fully customisable β colours, border, font, shape and icon
- Multiple Badges can be defined per column and selectively rendered using a Rule
- Array columns render one pill per element (with spacing and overflow options)
- Column-level options control inner padding, cell chrome behind the pills and alignment
The Badge Style renders the text of a Cell inside a "Badge" (sometimes known as a label).
The Badge can be fully styled, i.e. coloured, given a shape and border etc.
Caution
Badges can only be applied to Numeric, String or array (textArray / numberArray) columns
Multiple Badges can be provided for the same Column using Rules.
Badges can optionally include an Icon to display next to the text.
Hint
It is also possible to provide an Icon-only Badge where no text is displayed
Anatomy
A Badge Style is composed of one or more pills plus a set of column-level options.
Each pill has:
- A
PillStyleβ back / fore / border colour, font weight / style, text decoration - A
ShapeβPill,Rounded(default) orSquare - The cell text rendered inside the pill
- An optional
IconPropertiesgroup β System or CustomIcon, drawn at theStart(default) orEndof the pill (Position), with optionalGapandIconOnly - An optional Rule (
PredicateorExpression) that decides whether the pill renders for a given cell
Note
- Pills are evaluated top-down β the first matching Badge in the
Badgesarray wins - For array columns (
textArray/numberArray), AdapTable draws one pill per element
Column-level options on BadgeStyle apply to every pill in the column:
Densityβ inner padding preset (Compact/Normal/Comfortable)Cellβ chrome of the cell behind the pills (background, border, radius)Font.Alignmentβ positions the badge row (Left/Center/Right) within the cellSpacingandOverflowModeβ how multiple pills lay out in array cells (gap; truncate / wrap / scroll)
Breaking Change
In AdapTable 23 a new PillStyle was introduced and improvements were made to radius, shape, and aligment
- Overview demo β five columns in one grid (see the focused demos below for one idea per sandpack):
- name β single gray pill (
Density: Compact) - Language β icon-only pills per language (custom inline icons; no
PillStyle) - License β three rules with different
PillStylecolours - Closed Issues β three numeric rules with system icons (
Density: Comfortable) - topics β array column: per-topic rules, default fallback pill,
OverflowMode: Wrap
- name β single gray pill (
Badge UI Options
There are many options available to control the look and feel of the Badge (and the containing Cell).
Pill Style
Each Badge's pill is styled via the PillStyle property.
Hint
PillStyle is optional β when omitted, the Badge displays with default chrome (useful for icon-only Badges)
This is a cut-down subset of Adaptable Style containing just the properties that are relevant:
BackColorβ pill background colourForeColorβ pill text / icon colourBorderColorβ optional 1px pill borderFontWeightβ'Normal'or'Bold'FontStyleβ'Normal'or'Italic'TextDecorationβ'None','Underline','Overline'or'LineThrough'
Note
- Corner radius is not on
PillStyleβ use theShapetoken instead - Pills inherit nothing from a Format Column; Styled Columns own their pill rendering completely
Shape
Each Badge can declare a Shape token instead of reaching for a pixel BorderRadius:
'Pill'β fully rounded ends'Rounded'β subtly rounded corners (~4px)'Square'β sharp corners
Caution
Shape is the only way to set corner radius β PillStyle does not expose a BorderRadius property
{
Shape: 'Pill',
PillStyle: { BackColor: 'DarkBlue', ForeColor: 'white' },
}Density
The Density property on BadgeStyle controls the inner padding for every badge in the column.
This ensures that a column reads as one consistent label set:
'Compact'β tight padding for dense grids'Normal'β balanced (default)'Comfortable'β looser, for low-density / large-font grids
{
ColumnId: 'topics',
Name: 'Topics Badges',
BadgeStyle: {
Density: 'Compact',
Badges: [/* ... */],
},
}Cell Style
The Cell property on BadgeStyle styles the chrome of the cell behind the pills β independently of the pills themselves.
It accepts a CellBoxStyle object with the standard cell-box properties:
BackColorβ cell background colourBorderColorβ cell border colourBorderRadiusβ cell corner radius (in pixels)
Note
Cellis optional β when unset, the cell inherits any matching Format Column Cell-box properties- When set,
Cellclaims the Cell slice: matching Format Column Cell-box properties are stripped so the two cannot fight
- License β column-level
Cell(background, border, radius) behind the pills, plusFont.Alignment: 'Center'for the whole badge row - Three
Predicaterules tint MIT / BSD / other licences β same pill styling idea as the overview demo, isolated here to show v23 column-level options
Row Alignment
By default the row of Badges in a cell flows from the left of the cell.
The Font.Alignment property on BadgeStyle positions the entire badge row horizontally within the cell:
'Left'(default)'Center''Right'
Note
- Only
Alignmentis meaningful on the column-levelFontfor a Badge column - Other
Fontproperties (ForeColor,FontWeight, etc.) belong on each pill'sPillStyle, not here - When set,
Font.AlignmentoverridesAlignmentfrom any matching Format Column
{
ColumnId: 'license',
Name: 'License Badges',
BadgeStyle: {
Font: {
Alignment: 'Center',
},
Badges: [/* ... */],
},
}Rules
Which pill is shown for each cell is decided by each badge's optional Rule β AdapTable walks the Badges array top-down and uses the first match.
A Rule can be supplied in either form:
Predicateβ system or Custom Predicate (used in most demos today)Expressionβ anAdaptableBooleanQuerywhen you need richer logic
If a badge has no Rule, it matches every cell β put exactly one such badge at the end of the array as a fallback (e.g. a default gray pill on an array column).
Hint
- Multiple badges per column let you vary
PillStyle,ShapeandIconby value - For instance, you can have a different colour per status or licence type
- This example contains a Badge Style on the Country column
- Each country's Badge shows a different style based on a bespoke Rule
Icons
Badges can optionally include an Icon for extra decoration in addition to the Style.
They are defined using the IconProperties object which nests 4 main Icon-related properties:
| Property | Description |
|---|---|
Icon | The Icon itself (of type Adaptable Icon and most commonly a System Icon) |
Position | 'Start' (default value) or'End' |
Gap | Pixel gap between Icon and Pill text (falls back to column Density preset when omitted) |
IconOnly | Set to true to hide Pill text and show only the icon (see Icon Only Badges) |
Breaking Change
- Prior to AdapTable 23 these were four flat properties (
Icon,IconPosition,IconGap,IconOnly) on the Badge - The Migration Helper updates existing configurations automatically
Icon Placement
The Position and Gap properties control where the icon sits in the pill and how much breathing room it gets:
IconProperties: {
Icon: { name: 'alert' },
Position: 'End',
Gap: 6,
},
PillStyle: { BackColor: 'Red', ForeColor: 'white' },Custom Icons
Alternatively, the Icon in the Badge can be a Custom Icon provided by the developer at design-time.
Custom Icons can be defined "inline" or supplied using the customIcons property in User Interface Options.
Hint
- The advantages of using the
customIconsproperty is that Icons can be re-used (e.g. in Buttons) - It also allows run-time users to create Badge Styles that use custom icons as they will appear in the icon dropdown
- This example also contains a Badge Style on the Country column
- Each country's Badge includes an icon that was provided in
customIconsin User Interface Options
Icon Only Badges
It is possible to render a Badge where only the Icon is visible (without any cell text displayed).
This is done by setting IconProperties.IconOnly to true.
{
IconProperties: {
Icon: { name: 'star' },
IconOnly: true,
},
PillStyle: { BackColor: 'Gold' },
}Hint
- Prior to AdapTable 23 this was the recommended way to display only an icon in an AdapTable Column
- However the new Icon Styled Column supports this in a more powerful and intuitive way and includes presets
- This example contains 2 Badge Styles that display the Icon only (and no cell text):
Code- uses the same set of Custom Icons that we provide in the demo above (and has no style for the Badge applied)Rating- uses an AdapTable Icon and does have a style (of gray back colour)
Arrays
Badges can be applied to multiple items in the same cell.
Caution
The Column definition needs to have a Cell Data Type of textArray or numberArray
By default AdapTable will apply the same Badge style to every item in the Array.
However users can create multiple Badges for an Array column, with each having its own Rule and Style.
Note
There is no limit for the number of Badges which an array-based Column can contain
- This example applies a Badge Style to 2 array-based Columns:
Institutionscolumn (string) - we created 7 Badges each with a Rule (per institution), and a (Green) Badge for institutions which do not meet any PredicateAwardscolumn (numeric) - a single Badge Style for all values (and no Rules)
Spacing & Overflow
When rendering multiple badges side-by-side, two further options are available:
Spacing(number, px β default4) β sets the gap between adjacent badgesOverflowMode(default'Truncate') β how badges lay out when the cell is too narrow:'Truncate'β single line; cell clips overflow (legacy behaviour)'Wrap'β wrap onto subsequent lines (works best withautoRowHeightor a tallrowHeight)'Scroll'β single line; the cell becomes horizontally scrollable
{
ColumnId: 'topics',
Name: 'Topics Badges',
BadgeStyle: {
Density: 'Compact',
Spacing: 4,
OverflowMode: 'Wrap',
Badges: [/* ... */],
},
}Custom Predicates
The Badge Style can use a Custom Predicate in a Predicate rule when many values need grouping (e.g. region flags on an array column).
Hint
- This is very useful if there are many different cell values and a lookup function is required
- It is also useful in Array Columns where you wish to group similar values together
- This example applies a Badge to the
Institutionscolumn (similar to the demo above) - However we also create 4 Custom Predicates for
UK,US,EuropeanandAsianinstitutions - We have created 4 Badges - one for each Custom Predicate - which displays an appropriate flag
Defining Badge Styles
Badge Styles are provided at design-time through Styled Column Initial Adaptable State.
Developer Guide
Providing a Badge Style in Styled Column State
const initialState: InitialState = {
StyledColumn: {
StyledColumns: [
{
ColumnId: 'closed_issues_count',
Name: 'Closed Issues Badges',
BadgeStyle: {
Density: 'Compact',
Badges: [
{
Predicate: {
PredicateId: 'LessThan',
Inputs: [1000],
},
Shape: 'Pill',
IconProperties: {
Icon: {
name: 'alert',
},
Position: 'Start',
},
PillStyle: {
BackColor: 'Red',
ForeColor: 'white',
},
},
{
Predicate: {
PredicateId: 'LessThan',
Inputs: [10000],
},
Shape: 'Rounded',
IconProperties: {
Icon: {
name: 'flag',
},
},
PillStyle: {
BackColor: 'Orange',
ForeColor: 'white',
},
},
{
Shape: 'Square',
IconProperties: {
Icon: {
name: 'checked',
},
},
PillStyle: {
BackColor: 'Green',
ForeColor: 'white',
},
},
],
},
},
],
},
};Supply 3 mandatory properties:
ColumnIdβ Id of Column on which the Badge Style should renderNameβ a unique name for the Styled ColumnBadgeStyleobject β wrapper containing Badge configuration
The BadgeStyle object accepts several column-wide options that apply to every badge in the column:
Densityβ inner padding:'Compact','Normal','Comfortable'OverflowMode(array columns) β how badges lay out when a cell is too narrow:'Truncate'(default),'Wrap'or'Scroll'CellβCellBoxStyle(background, border, radius) drawn behind the pillsFont.Alignmentβ positions the badge row (Left/Center/Right) within the cell; overrides any matching Format Column alignmentSpacing(array columns) β pixel gap between adjacent Badges
The Badges array contains each distinctly styled Badge in the Column.
Each Badge has its own optional Rule, Shape, Pill Style and Icon.
Note
Badges are evaluated top-down β first matching Badge in array wins
Each badge can include a Predicate or Expression. If omitted, the badge matches every cell (use once, as the last entry, for a fallback pill).
Use the Shape token to control the pill's corner radius:
'Pill'β fully rounded ends'Rounded'(default) β subtly rounded corners (~4px)'Square'β sharp corners
Caution
Shape is only way to set corner radius (not available in PillStyle)
Use PillStyle for the pill's visual properties (subset of Adaptable Style):
Note
- Pills don't inherit from Format Column
- Pill font size is controlled by column
Density, notPillStyle
Display an icon inside the pill via the IconProperties group:
IconProperties.Icon(required when the group is present) β an Adaptable Icon. Either an AdapTable System icon (e.g.{ name: 'alert' }) or a Custom icon provided inline or via customIconsIconProperties.Positionβ'Start'(default) or'End'IconProperties.Gapβ pixel gap between the icon and the pill text (falls back to the columnDensitypreset when omitted)IconProperties.IconOnlyβtrueto hide the cell text and show only the icon
Creating Badge Styles
Badge Styles can be created at run-time using the Styled Column UI Wizard.
UI Step by Step Guide
Creating a Badge Style using the Styled Column Wizard
FAQ
Can we create multiple Badge Styles? Yes, you can have as many per column as required; each should have its own, non-overlapping, Predicate- or Expression-based Rule.
Can I have differently styled Badges on the same array cell?
Yes β Badges on array columns (textArray / numberArray) work the same way as on scalar columns: each BadgeStyleDefinition has its own PillStyle, Shape, Icon and Rule, and AdapTable picks the first matching Badge per array element.
Do you support Badges on Date Columns? Not currently, but we might add this in a future version if there is demand