Cell Styling in React Data Grid
Customizing the grid cell styles allows you to modify the appearance of cells in the Syncfusion® React Data Grid component to meet your design requirements. You can customize the font, background color, and other styles of the cells.
Dynamic cell styling
The cellClass property in the Syncfusion React Data Grid applies styles to individual cells based on their values. This enables dynamic formatting that highlights key data, improves readability, and adds visual clarity across the grid.
In the example, conditional styling applies to cases such as:
- Performance Ratings: Colored borders based on rating (e.g., green for Excellent, red for Poor).
- Project Status: Colored labels to show status like Completed, In Progress, On Hold, or Delayed.
- Productivity & Attendance: High performers and poor attendance are visually emphasized.
- Targets Achieved: Star icons (★) and gradient backgrounds for top achievers.
Cell font styling
Apply global font styling across all grid cells by targeting the .sf-grid .sf-grid-content-row .sf-cell selector in your stylesheet. This allows centralized control over font weight, size, style, and opacity. For conditional styling of specific cells, the cellClass property can be used, which receives the following arguments:
column:The column definition object, containing metadata such as field name and configuration.data:The full data object for the row, allowing contextual evaluation of the cell's value.rowIndex:The index of the current row, useful for alternating styles.cellType:The type of the current cell (content or header), useful for applying styles based on cell category.
For example, font styling can be applied as follows:
- Apply
.critical-cellto display bold, condensed, uppercase fonts with subtle text shadows. - Apply
.lowrisk-cellto use lightweight fonts with reduced opacity for less prominent items.
Customize headers and content
The cellClass properties in the grid allow customization of header (<th>) and content (<td>) cells through CSS class assignment.
cellClass(column, rowIndex, cellType, data):Adds a CSS class to each cell (<th>andtd). enabling styling based on the column name, index, cellType and row data.
When
cellClassproperty is defined as a function, it runs every time a cell renders or updates. In grids with many cells or frequent changes, this repeated execution increases processing load and can slow down performance. To improve efficiency, use thecolumn templatefeature for cell customization instead of function-based class assignments.