Search results

Cell

Displaying HTML Content

The HTML tags can be displayed in the Grid header and content by enabling the disableHtmlEncode property.

Source
Preview
index.tsx
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { Grid, GridComponent, ColumnsDirective, ColumnDirective } from '@syncfusion/ej2-react-grids';
import { data } from '../datasource.ts';

class App extends React.Component<{}, {}>{
    render() {
        return (<div>
        <GridComponent dataSource={data} height={315}>
            <ColumnsDirective>
                <ColumnDirective field="OrderID" headerText="<span> Order ID </span>" disableHtmlEncode={true} width="140" textAlign="Right"></ColumnDirective>
                <ColumnDirective field="CustomerID" headerText="<span> Customer ID </span>" disableHtmlEncode={false} width="100"></ColumnDirective>
                <ColumnDirective field="EmployeeID" headerText="Employee ID" width="100" textAlign="Right"></ColumnDirective>
                <ColumnDirective field="Freight" headerText="Freight" width="80" format="C2" textAlign="Right"></ColumnDirective>
                <ColumnDirective field="ShipCountry" headerText="Ship Country" width="100"></ColumnDirective>
            </ColumnsDirective>
        </GridComponent>
        </div>)
    }
};
ReactDOM.render(<App />, document.getElementById('grid'));

Customize Cell Styles

The appearance of cells can be customized by using the queryCellInfo event. The queryCellInfo event triggers for every cell. In that event handler, you can get QueryCellInfoEventArgs that contains the details of the cell.

Source
Preview
index.tsx
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { Grid, GridComponent, ColumnsDirective, ColumnDirective } from '@syncfusion/ej2-react-grids';
import { data } from '../datasource.ts';

class App extends React.Component<{}, {}>{
    public customizeCell(args) {
        if(args.column.field === "Freight") {
            if (args.data["Freight"] < 30){
                args.cell.classList.add('below-30');
            } else if(args.data["Freight"] < 80 ) {
                args.cell.classList.add('below-80');
            } else {
                args.cell.classList.add('above-80');
            }
        }
    }
    render() {
        return (<div>
        <GridComponent dataSource={data} height={315} enableHover={false} allowSelection={false} queryCellInfo={this.customizeCell.bind(this)}>
            <ColumnsDirective>
                <ColumnDirective field="OrderID" headerText="Order ID" width="100" textAlign="Right"></ColumnDirective>
                <ColumnDirective field="CustomerID" headerText="Customer ID" width="100"></ColumnDirective>
                <ColumnDirective field="EmployeeID" headerText="Employee ID" width="100" textAlign="Right"></ColumnDirective>
                <ColumnDirective field="Freight" headerText="Freight" width="80" textAlign="Right" format="C2" ></ColumnDirective>
                <ColumnDirective field="ShipCountry" headerText="Ship Country" width="100"></ColumnDirective>
            </ColumnsDirective>
        </GridComponent>
        </div>)
    }
};
ReactDOM.render(<App />, document.getElementById('grid'));

Auto Wrap

The auto wrap allows the cell content of the grid to wrap to the next line when it exceeds the boundary of the cell width. The Cell Content wrapping works based on the position of white space between words. To enable auto wrap, set the allowTextWrap property to true. You can configure the auto wrap mode by setting the textWrapSettings.wrapMode property.

There are three types of wrapMode. They are

  • Both - The Both value is set by default. Auto wrap will be enabled for both content and Header.
  • Header - Auto wrap will be enabled only for header.
  • Content - Auto wrap will be enabled only for content.

Note: When a column width is not specified, then auto wrap of columns will be adjusted with respect to the grid’s width.

In the below example, the textWrapSettings.wrapMode is set as Content.

Source
Preview
index.tsx
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { Grid, GridComponent, Inject, ColumnsDirective, ColumnDirective, Page, WrapMode } from '@syncfusion/ej2-react-grids';
import { inventoryData } from '../datasource.ts';

class App extends React.Component<{}, {}>{
    public settings: WrapMode = { wrapMode: 'Content' };
    render() {
        return (<div>
        <GridComponent dataSource={inventoryData} allowPaging={true} allowTextWrap={true} textWrapSettings={this.settings} height='400'>
            <ColumnsDirective>
                <ColumnDirective field='Inventor' headerText='Inventor' width='180' textAlign='Right'></ColumnDirective>
                <ColumnDirective field='NumberofPatentFamilies' headerText='Number of Patent Families' width='180' textAlign='Right'></ColumnDirective>
                <ColumnDirective field='Country' headerText='Country' width="140" />
                <ColumnDirective field='Active' headerText='Active' width='120' />
                <ColumnDirective field='Mainfieldsofinvention' headerText='Main Fields of Invention' width='200'></ColumnDirective>
            </ColumnsDirective>
            <Inject services={[Page]} />
        </GridComponent>
        </div>)
    }
};
ReactDOM.render(<App />, document.getElementById('grid'));

Custom Attributes

You can customize the grid cells by adding a CSS class to the customAttribute property of the column.

.e-attr {
    background: #d7f0f4;
}
<ColumnDirective
    field="ShipCity" headerText="Ship City" :customAttributes={{class: 'e-attr'}} width="80">
</ColumnDirective>

In the below example, we have customized the cells of OrderID and ShipCity columns.

Source
Preview
index.tsx
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { Grid, GridComponent, ColumnsDirective, ColumnDirective } from '@syncfusion/ej2-react-grids';
import { data } from '../datasource.ts';

class App extends React.Component<{}, {}>{

    render() {
        return (<div>
        <GridComponent dataSource={data} height={315}>
            <ColumnsDirective>
                <ColumnDirective field="OrderID" headerText="Order ID" customAttributes={{class: 'e-attr'}} width="100" textAlign="Right"></ColumnDirective>
                <ColumnDirective field="CustomerID" headerText="Customer ID" width="100"></ColumnDirective>
                <ColumnDirective field="ShipCity" headerText="Ship City" customAttributes={{class: 'e-attr'}} width="100"></ColumnDirective>
                <ColumnDirective field="ShipCountry" headerText="Ship Country" width="100"></ColumnDirective>
            </ColumnsDirective>
        </GridComponent>
        </div>)
    }
};
ReactDOM.render(<App />, document.getElementById('grid'));

Grid Lines

The gridLines have option to display cell border and it can be defined by the gridLines property.

The available modes of grid lines are:

Modes Actions
Both Displays both the horizontal and vertical grid lines.
None No grid lines are displayed.
Horizontal Displays the horizontal grid lines only.
Vertical Displays the vertical grid lines only.
Default Displays grid lines based on the theme.
Source
Preview
index.tsx
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { Grid, GridComponent, ColumnsDirective, ColumnDirective } from '@syncfusion/ej2-react-grids';
import { inventoryData } from '../datasource.ts';

class App extends React.Component<{}, {}>{
    render() {
        return (<div>
        <GridComponent dataSource={inventoryData} gridLines='Both' height={315}>
            <ColumnsDirective>
                <ColumnDirective field='Inventor' headerText='Inventor' width='180' textAlign='Right'></ColumnDirective>
                <ColumnDirective field='NumberofPatentFamilies' headerText='Number of Patent Families' width='180' textAlign='Right'></ColumnDirective>
                <ColumnDirective field='Country' headerText='Country' width="140" />
                <ColumnDirective field='Active' headerText='Active' width='120' />
                <ColumnDirective field='Mainfieldsofinvention' headerText='Main Fields of Invention' width='200'></ColumnDirective>
            </ColumnsDirective>
        </GridComponent>
        </div>)
    }
};
ReactDOM.render(<App />, document.getElementById('grid'));

By default, the grid renders with Default mode.

Clip Mode

The clip mode provides options to display its overflow cell content and it can be defined by the columns.clipMode property.

There are three types of clipMode. They are:

  • Clip: Truncates the cell content when it overflows its area.
  • Ellipsis: Displays ellipsis when the cell content overflows its area.
  • EllipsisWithTooltip: Displays ellipsis when the cell content overflows its area, also it will display the tooltip while hover on ellipsis is applied.
Source
Preview
index.tsx
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { Grid, GridComponent, Inject, ColumnsDirective, ColumnDirective, Page } from '@syncfusion/ej2-react-grids';
import { inventoryData } from '../datasource.ts';

class App extends React.Component<{}, {}>{
    render() {
        return (<div>
        <GridComponent dataSource={inventoryData} allowPaging={true}>
            <ColumnsDirective>
                <ColumnDirective field='Inventor' headerText='Name of the Inventor' clipMode='Clip' width="80"></ColumnDirective>
                <ColumnDirective field='NumberofPatentFamilies' headerText='Number of Patent Families' clipMode='Ellipsis' width="100"></ColumnDirective>
                <ColumnDirective field='Country' headerText='Country' width="80" />
                <ColumnDirective field='Active' headerText='Active' width="100" />
                <ColumnDirective field='Mainfieldsofinvention' headerText='Main Fields of Invention' clipMode='EllipsisWithTooltip' width="100"></ColumnDirective>
            </ColumnsDirective>
            <Inject services={[Page]} />
        </GridComponent>
        </div>)
    }
};
ReactDOM.render(<App />, document.getElementById('grid'));

By default, columns.clipMode value is Ellipsis.