Search results

Scrolling

The scrollbar will be displayed in the grid when content exceeds the element width or height. The vertical and horizontal scrollbars will be displayed based on the following criteria:

  • The vertical scrollbar appears when the total height of rows present in the grid exceeds its element height.
  • The horizontal scrollbar appears when the sum of columns width exceeds the grid element width.
  • The height and width are used to set the grid height and width, respectively.

The default value for height and width is auto.

Set width and height

To specify the width and height of scroller in pixel, set the pixel value as number.

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

class App extends React.Component<{}, {}>{
    public data: Object[] = data;
    render() {
        return <GridComponent dataSource={this.data} height={315} width={400}>
                <ColumnsDirective>
                 <ColumnDirective field='OrderID' width='120' textAlign="Right"></ColumnDirective>
                 <ColumnDirective field='CustomerID' width='150'></ColumnDirective>
                 <ColumnDirective field='EmployeeID' width='120' textAlign="Right"></ColumnDirective>
                 <ColumnDirective field='ShipCity' width='150'></ColumnDirective>
                 <ColumnDirective field='ShipCountry' width='150'></ColumnDirective>
                 <ColumnDirective field='ShipName' width='150'></ColumnDirective>
                </ColumnsDirective>
               </GridComponent>
    }
}
ReactDOM.render(<App />, document.getElementById('grid'));

Responsive with parent container

Specify the width and height as 100% to make the grid element fill its parent container. Setting the height to 100% requires the grid parent element to have explicit height.

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

class App extends React.Component {
    public data: Object[] = data;
    render() {
        return <GridComponent dataSource={this.data} height="100%" width="100%">
                <ColumnsDirective>
                 <ColumnDirective field='OrderID' width='120' textAlign="Right"></ColumnDirective>
                 <ColumnDirective field='CustomerID' width='150'></ColumnDirective>
                 <ColumnDirective field='EmployeeID' width='120' textAlign="Right"></ColumnDirective>
                 <ColumnDirective field='ShipCity' width='150'></ColumnDirective>
                 <ColumnDirective field='ShipCountry' width='150'></ColumnDirective>
                 <ColumnDirective field='ShipName' width='150'></ColumnDirective>
                </ColumnsDirective>
               </GridComponent>
    }
}
ReactDOM.render(<App />, document.getElementById('grid'));

Scroll To Selected Row

You can scroll the grid content to the selected row position by using the rowSelected event.

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

class App extends React.Component {
    private grid: GridComponent;
    private numeric;
    public data: Object[] = data;
    public onChange(){
      this.grid.selectionModule.selectRow(parseInt(this.numeric.getText(), 10));
    }
    public rowSelected(args: RowSelectEventArgs) {
        let rowHeight: number = this.grid.getRows()[this.grid.getSelectedRowIndexes()[0]].scrollHeight;
        this.grid.getContent().children[0].scrollTop = rowHeight * this.grid.getSelectedRowIndexes()[0];
    }
    render() {
        return (<div>
              <NumericTextBoxComponent format={'N'} placeholder={'Enter index to select a row'} width={200} showSpinButton={false} change={this.onChange.bind(this)} ref={n=> this.numeric = n}></NumericTextBoxComponent>
              <GridComponent dataSource={this.data} height="275" width="100%" rowSelected={this.rowSelected.bind(this)} ref={g => this.grid = g}>
                <ColumnsDirective>
                 <ColumnDirective field='OrderID' width='120' textAlign="Right"></ColumnDirective>
                 <ColumnDirective field='CustomerID' width='150'></ColumnDirective>
                 <ColumnDirective field='EmployeeID' width='120' textAlign="Right"></ColumnDirective>
                 <ColumnDirective field='ShipCity' width='150'></ColumnDirective>
                </ColumnsDirective>
               </GridComponent></div>)
    }
}
ReactDOM.render(<App />, document.getElementById('grid'));

Frozen rows and columns

Frozen rows and columns provides an option to make rows and columns always visible in the top and left side of the grid while scrolling.

To use frozen rows and columns support, inject the Freeze module in the grid.

In this demo, the frozenColumns is set as ‘2’ and the frozenRows is set as ‘3’. Hence, the left two columns and top three rows are frozen.

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

class App extends React.Component {
    private grid: GridComponent;
    public data: Object[] = data;
    render() {
        return (<div>
              <GridComponent dataSource={this.data} height="315" frozenRows={3} frozenColumns={2} allowSelection={false} enableHover={false}>
                <ColumnsDirective>
                 <ColumnDirective field='OrderID' width='120' textAlign="Right"></ColumnDirective>
                 <ColumnDirective field='CustomerID' width='150'></ColumnDirective>
                 <ColumnDirective field='OrderDate' width='130' format='yMd' textAlign='Right'></ColumnDirective>
                 <ColumnDirective field='EmployeeID' width='120' textAlign="Right"></ColumnDirective>
                 <ColumnDirective field='ShipName' width='150'></ColumnDirective>
                 <ColumnDirective field='ShipAddress' width='170'></ColumnDirective>
                 <ColumnDirective field='ShipCity' width='150'></ColumnDirective>
                 <ColumnDirective field='ShipCountry' width='150'></ColumnDirective>
                 <ColumnDirective field='ShipRegion' width='150'></ColumnDirective>
                 <ColumnDirective field='ShipPostalCode' width='150'></ColumnDirective>
                 <ColumnDirective field='Freight' width='120'></ColumnDirective>
                </ColumnsDirective>
                <Inject services={[Freeze, Selection]} />
               </GridComponent></div>)
    }
}
ReactDOM.render(<App />, document.getElementById('grid'));
  • The allowScrolling must be true while giving frozen rows and columns.
  • Frozen rows and columns should not be set outside the grid view port.

Limitations

The following features are not supported in frozen rows and columns:

  • Grouping
  • Row Template
  • Detail Template
  • Hierarchy Grid