Styling

The KendoReact Data Grid enables you to style its columns, rows, and cells.

Columns

To style the columns of the Grid, either:

Adding Custom Cells

Adding a custom cell for the Grid columns allows you to change the appearance of that cell based on the provided value. By using the custom-cell approach, you can include icons, buttons, links, or any other HTML elements in the cell.

import React from 'react';
import ReactDOM from 'react-dom';
import { Grid, GridColumn } from '@progress/kendo-react-grid';

import products from './products.json';

class cellWithBackGround extends React.Component {
    render() {
        const examplePrice = this.props.dataItem.UnitPrice < 15;

        const icon = examplePrice ?
            <span className="k-icon k-i-sort-desc-sm" /> :
            <span className="k-icon k-i-sort-asc-sm" />;

        const style = {
            backgroundColor: examplePrice ?
                "rgb(243, 23, 0, 0.32)" :
                "rgb(55, 180, 0,0.32)"
        };

        return (
            <td style={style}>
                {this.props.dataItem[this.props.field]} {icon}
            </td>
        );
    }
}

const App = (props) => (
    <Grid data={props.data} style={{ height: '240px' }}>
        <GridColumn field="ProductName" title="Product Name" />
        <GridColumn field="UnitPrice" title="Units Price" cell={cellWithBackGround} />
        <GridColumn field="UnitsOnOrder" title="Units On Order" />
        <GridColumn field="ReorderLevel" title="Reorder Level" />
    </Grid>
);

ReactDOM.render(<App data={products} />, document.querySelector('my-app'));

Adding Custom Header Cells

Adding a custom headerCell for the column header of the Grid allows you to change the appearance and to include icons, buttons, links, or any other HTML elements in that header.

import React from 'react';
import ReactDOM from 'react-dom';
import { Grid, GridColumn } from '@progress/kendo-react-grid';
import products from './products.json';
class ProductNameHeader extends React.Component {
    render() {
        return (
            <a className="k-link" onClick={this.props.onClick}>
            <span className="k-icon k-i-cart"></span>
            <span style={{color: "#53d2fa"}}>{this.props.title}</span>
                {this.props.children}
            </a>
        );
    }
  }
class App extends React.Component {
    render() {
        return (
            <div>
                <Grid
                    data={products.slice(0,5)}
                >
                    <GridColumn field="ProductID" title="ID" width="40px" />
                    <GridColumn field="ProductName" title="Product Name" width="250px" headerCell={ProductNameHeader}/>
                    <GridColumn field="Category.CategoryName" title="CategoryName" />
                    <GridColumn field="UnitPrice" title="Price" width="80px" />
                    <GridColumn field="UnitsInStock" title="In stock" width="80px" />
                </Grid>
            </div>
        );
    }
}
ReactDOM.render(
    <App/>, document.querySelector('my-app'));

Adding Class Names

The className property applies additional class to the td element and can be used for styling the background, text color, text alignment, and other styling options of the Grid.

<GridColumn field="ProductName" title="Product Name" className="product-name">
product-name {
    color: "white";
    background-color: "#888888"
}

Rows

To style the rows of the Grid, utilize the rowRender function. rowRender allows you to modify the appearance of the rows based on the provided values.

import React from 'react';
import ReactDOM from 'react-dom';
import { Grid, GridColumn as Column } from '@progress/kendo-react-grid';

import products from './products.json';

class App extends React.Component {
    rowRender(trElement, props) {
        const available = !props.dataItem.Discontinued;
        const green = { backgroundColor: "rgb(55, 180, 0,0.32)" };
        const red = { backgroundColor: "rgb(243, 23, 0, 0.32)" };
        const trProps = { style: available ? green : red };
        return React.cloneElement(trElement, { ...trProps }, trElement.props.children);
    }

    render() {
        return (
            <div>
                <Grid
                    data={products}
                    style={{ height: '400px' }}
                    rowRender={this.rowRender}
                >
                    <Column field="ProductName" title="Product Name" />
                    <Column field="UnitsInStock" title="Units In Stock" />
                    <Column field="UnitsOnOrder" title="Units On Order" />
                    <Column field="Discontinued" />
                </Grid>
            </div>
        );
    }
}

ReactDOM.render(<App />, document.querySelector('my-app'));

Individual Elements

You can individually style the elements of the Grid by using CSS.

The Grid provides multiple elements that can be individually styled. Before you apply the styling options to the desired elements, inspect the element and use selectors of higher priority.

Filter Icons

The following example demonstrates how to style the appearance of the filter icon in the Grid.

.k-dropdown-wrap>.k-select>.k-i-filter {
    color:"white"
}

Sort Icons

The following example demonstrates how to style the appearance of the sort ascending-order icon in the Grid.

.k-header>.k-link>.k-i-sort-asc-sm {
    color:"red"
}

Page Numbers

The following example demonstrates how to style the appearance of the page numbers in the Grid.

.k-pager-numbers .k-link, .k-pager-numbers .k-link:link {
    color: "black";
}

Conditional Styling

You can use the custom-cell approach of the Grid to change the appearance of the cells on condition and based on the provided value.

import React from 'react';
import ReactDOM from 'react-dom';
import { Grid, GridColumn as Column } from '@progress/kendo-react-grid';

class App extends React.Component {
    state = {
        data: [
            { ProductName: "Tea", UnitPrice: 18, UnitsOnOrder: 20, inEdit: true },
            { ProductName: "Coffee", UnitPrice: 10, UnitsOnOrder: 55, inEdit: true }
        ]
    }

    cellWithBackGround = (props) => {
        const product = props.dataItem.UnitPrice * props.dataItem.UnitsOnOrder;
        if (product < 400) {
            return (
                <td style={{ backgroundColor: "rgb(55, 180, 0,0.32)" }}>
                    {product}
                </td>
            );
        }
        return (
            <td style={{ backgroundColor: "rgb(243, 23, 0, 0.32)" }}>
                {product} <span>Maximum exceeded</span>
            </td>
        );
    };

    itemChange = (event) => {
        event.dataItem[event.field] = event.value;
        this.setState({ ...this.state });
    }

    render() {
        return (
            <div>
                <Grid
                    data={this.state.data}
                    scrollable="none"
                    editField="inEdit"
                    onItemChange={this.itemChange}
                >
                    <Column field="ProductName" title="Product Name" editable={false} />
                    <Column field="UnitPrice" title="Units Price" editor="numeric" />
                    <Column field="UnitsOnOrder" title="Units On Order" editor="numeric" />
                    <Column title="Total value" cell={this.cellWithBackGround} />
                </Grid>
            </div>
        );
    }
}
ReactDOM.render(<App />, document.querySelector('my-app'));
 /