Column Styling
Using the column style
The most straightforward way to style the cells in a column is to use the
column.style property as an object.const column = {
firstName: {
style: {
color: 'red',
fontWeight: 'bold',
},
},
};#
Using column.style as an object
loading demo…
The
column.style property can either be an object (of type React.CSSProperties) or a function that returns an object (of the same type).Using functions for the
column.style property allows you to style the cells based on the cell's value or other properties.const columns: InfiniteTablePropColumns<Developer> = {
salary: {
field: 'salary',
type: 'number',
style: ({ value, data, column, rowInfo }) => {
return {
color: value && value > 100_000 ? 'red' : 'tomato',
};
},
},
};#
Using column.style as a function
loading demo…
If defined as a function, the
column.style accepts an object as a parameter, which has the following properties:column- the current column where the style is being applieddata- the data object for the current row. The type of this object isDATA_TYPE | Partial<DATA_TYPE> | null. For regular rows, it will be of typeDATA_TYPE, while for group rows it will bePartial<DATA_TYPE>. For rows not yet loaded (because of batching being used), it will benull.rowInfo- the information about the current row - see Using RowInfo for more details.value- the underlying value of the current cell - will generally bedata[column.field], if the column is bound to afieldproperty
Using the column className
Mirroring the behavior already described for the
column.style property, the column.className property can be used to apply a CSS class to the cells in a column.It can be used as a string or a function that returns a string.
const columns = {
firstName: {
className: 'first-name-column',
},
};#
Using column.className as an string
loading demo…
Using functions for the
column.className property allows you to style the cells based on the cell's data/value/rowInfo etc.const columns: InfiniteTablePropColumns<Developer> = {
salary: {
field: 'salary',
type: 'number',
className: ({ value, data, column, rowInfo }) => {
return value && value > 100_000 ? 'red-color' : 'tomato-color';
},
},
}#
Using column.className as a function
loading demo…