#Styled Cells
Styled cells style and format grid cells declaratively: each styled cell pairs a scope (which columns it targets) with a style (colors, font, alignment), an optional display format (text, number or date formatting) and an optional condition (an AdaptableQL expression that decides row by row whether the style applies).
Styled cells are defined globally in the Adaptable state (under
styledCell), but they only apply to the views that list them in their
styledCells property — so different views can activate different styles over
the same data.
const state: AdaptableUserState = {
// ... globalEntities: { availableColumns },
styledCell: {
salary: {
// 'salary' is the id of the styled cell definition
label: 'Salary formatting',
scope: {
columns: ['salary'],
},
format: { cellFormatType: 'number', prefix: '$ ', maxFractionDigits: 0 },
style: { fontWeight: 'bold', textAlign: 'right' },
},
},
view: {
currentViewId: 'default',
views: [
{
id: 'default',
label: 'All rows',
styledCells: ['salary'],
},
],
},
};Styled cells are not applied in views that do not list them in their
styledCells property.
The salary column is formatted as a currency ($ prefix, no fraction digits)
and rendered bold and right-aligned; the preferredLanguage column gets an
accent color.
#Conditional styles
A styled cell can carry a condition — a boolean AdaptableQL expression
evaluated per row.
The style (and format) only applies to the cells of rows where the expression is
true. The expression may reference any column, not just the ones in scope.
{
label: 'High salaries',
scope: { columns: ['salary'] },
condition: {
expression: '[salary] > 150000',
},
style: { background: '#fee2e2', color: '#b91c1c', fontWeight: 'bold' },
},Salaries over 150000 are highlighted, and the name columns are tinted blue for
rows where [preferredLanguage] = "TypeScript" — a condition on a column outside
the styled cell's scope.
#Scope
The scope decides which columns a styled cell targets:
columns— an explicit list of column ids.columnTypes/dataTypes— target every column of the given column type or data type (text,number,date, …).- No scope at all means the styled cell applies to every column.
#Order of styling
Multiple styled cells can hit the same cell. The order of the ids in the view's
styledCells array is the priority order: earlier entries win, later ones
only fill in properties the earlier ones left unset — styles are merged from
right to left, with the rightmost having the least priority.
const view: AdaptableTableView = {
id: 'default',
label: 'All rows',
// 'high-salary' wins over 'salary-base' where both apply
styledCells: ['high-salary', 'salary-base'],
};#Managing styled cells in the UI
The settings panel has a Styled Cells page where users can create, edit and delete styled cells — with a live preview of the style and format. The page shows the styled cells active in the current view as an ordered list that can be drag-reordered to change the priority (styles higher in the list win), with the remaining definitions below, ready to be added to the view. The editor distinguishes between all columns (no scope restriction — new columns are covered automatically) and an explicit column selection, which only ever targets the picked columns.
The editor is also available standalone as Adaptable.UI.StyledCellsManager
(needs only an Adaptable.Provider ancestor):
<Adaptable.Provider v-bind="props">
<Adaptable.UI />
<Adaptable.UI.StyledCellsManager />
</Adaptable.Provider>For fully custom UIs, the useStyledCells composable exposes the same
operations. It returns a ref of an object with them:
import { useStyledCells } from '@adaptabletools/datagrid-vue';
// in the setup of a component rendered inside the provider
const styledCellsRef = useStyledCells();
function onToolbarAction() {
// read `.value` when you need it (the template unwraps the ref)
const {
styledCells, // all styled cells defined in state
isInCurrentView, // (id) => boolean
createStyledCell, // (config, { addToCurrentView? }) => id
updateStyledCell, // (id, config) => void
deleteStyledCell, // (id) => void — also removed from every view
addToCurrentView,
removeFromCurrentView,
setCurrentViewStyledCells, // (orderedIds) => void — sets the priority order
} = styledCellsRef.value;
// ...
}