Hi Bok,
Thanks for contacting Syncfusion forum.
We have achieved your requirement “Dynamically create a Data Grid in React” using button click. In button click we have created our EJ2 Grid in React way using below code.
Please refer the below code example.
|
btnClick(args){
var data = [{ OrderID: 1, CustomerName: 'text' },
{ OrderID: 2, CustomerName: 'text2' },
{ OrderID: 2, CustomerName: 'text3' }]
ReactDOM.render(<div>
<GridComponent dataSource={data}>
<ColumnsDirective>
<ColumnDirective field='OrderID' headerText='Order ID' width='100' textAlign="Right"/>
<ColumnDirective field='CustomerName' headerText='Customer ID' width='100'/>
</ColumnsDirective>
</GridComponent>
</div>, args.target.nextElementSibling)
}
render() {
return (<div className='control-pane'>
<div className='control-section'>
<ButtonComponent cssClass='e-flat e-primary' ref={(scope) => { this.btnobj = scope; }} onClick={this.btnClick.bind(this)}>Create Grid</ButtonComponent>
<div id="Grid"></div>
</div>
</div>);
}
|
For more reference please refer to the below sample.
Likewise you can render our Grid as per your needs.
Please get back to us, if you need any further assistance.
Regards,
Thiyagu S