|
export class Sample extends SampleBase {
render() {
return (
<div className="control-pane">
<div className="control-section">
<GridComponent
dataSource={orderDetails}
ref={grid => (this.gridInstance = grid)}
allowPaging={true}
allowExcelExport={true}
allowPdfExport={true}
load={this.load}
>
<ColumnsDirective>
<ColumnDirective
field="OrderID"
headerText="Order ID"
width="120"
textAlign="Right"
template={rowData =><Router> <Link to={"/order/" + rowData.OrderID}> go to ID </Link></Router> } //define the <Router> tag here
></ColumnDirective>
</ColumnsDirective>
<Inject
services={[Page, Toolbar, ExcelExport, PdfExport, Group]}
/>
</GridComponent>
</div>
</div>
);
}
}
}
|
|
[App.tsx]
import * as React from "react";
import * as ReactDOM from 'react-dom';
import { BrowserRouter as Router, Switch, Route, Link } from "react-router-dom";
import Grid from './Grid';
import Home from './Home';
import Nav from './navpage';
export default class App extends React.Component<{}, {}> {
render() {
return (
<Router>
<div>
<ul>
<li><Link to={'/'}>Home</Link></li>
<li><Link to={'/Grid'}>Grid</Link></li>
</ul>
<hr />
<Switch>
<Route exact path='/' component={Home}></Route>
<Route exact path='/Grid' component={Grid}></Route>
<Route exact path='/navpage' component={Nav}></Route>
</Switch>
</div>
</Router>
);
}
}
ReactDOM.render(<App />, document.getElementById('grid'));
|
|
[Grid.tsx]
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import {
GridComponent, Sort, ColumnsDirective, ColumnDirective,
Inject, Page
} from '@syncfusion/ej2-react-grids';
import './App.css';
import { orderDetails } from './data';
export default class Grid extends React.Component<{}, {}> {
public gridObj: GridComponent | null;
public load(args: any): void {
}
public renderAnchor(args: any): void {
if (args.column.field == "CustomerID") {
//template create
ReactDOM.render(<a className='acrele' onClick={this.onChange.bind(this)} rel='nofollow' rel='nofollow' href='#'>{args.cell.innerText}</a>, args.cell)
}
}
public onChange(args: any) {
//call event when click the link
if (args.target.classList.contains('acrele')) {
let rowData: Object | null = this.gridObj ? this.state = { rData: this.gridObj.getRowInfo(args.target.parentElement).rowData } : null;
this.setState({ rData: rowData });
(this.props as any).history.push('/navpage') //navigate to new page
}
}
render() {
return (
<div>
<GridComponent dataSource={orderDetails} queryCellInfo={this.renderAnchor.bind(this)} ref={grid => this.gridObj = grid} allowPaging={true} load={this.load} allowSorting={true}>
<ColumnsDirective>
<ColumnDirective field='OrderID' headerText='ID' width='120' ></ColumnDirective>
<ColumnDirective field='CustomerID' headerText='CustomerID' width='160'></ColumnDirective>
<ColumnDirective field='Freight' headerText='Freight' width='160'></ColumnDirective>
</ColumnsDirective>
<Inject services={[Page, Sort]} />
</GridComponent>
</div>
);
}
}
ReactDOM.render(<Grid />, document.getElementById('grid'));
|