Skip to content

Instantly share code, notes, and snippets.

@MikeTatsky
Last active February 4, 2020 20:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MikeTatsky/a6902da3062962f672be01afcaa6f81a to your computer and use it in GitHub Desktop.
Save MikeTatsky/a6902da3062962f672be01afcaa6f81a to your computer and use it in GitHub Desktop.
React FancyGrid
import React, { Component } from 'react';
import { Fancy, Grid } from 'fancygrid-react';
import 'fancygrid/client/modules/sort.min';
import 'fancygrid/client/modules/dom.min';
import 'fancygrid/client/modules/edit.min';
import 'fancygrid/client/modules/grid.min';
import 'fancygrid/client/modules/selection.min';
import 'fancygrid/client/modules/menu.min';
import 'fancygrid/client/modules/exporter';
import 'fancygrid/client/modules/excel.min';
import 'fancygrid/client/fancy.min.css';
Fancy.stylesLoaded = true;
class App extends Component {
constructor(props) {
super(props);
}
render() {
return (
<div>
<Grid
title='My Grid'
selModel='rows'
theme='gray'
height={400}
width={500}
exporter={true}
defaults={{sortable: true}}
trackOver={true}
events={this.getEvents()}
columns={this.getColumns()}
contextmenu={true}
data={this.getData()}>
</Grid>
</div>
);
}
getColumns() {
return [{
type: 'select'
},{
index: 'company',
title: 'Company',
type: 'string',
width: 100
},{
index: 'name',
title: 'Name',
type: 'string',
width: 100
},{
index: 'surname',
title: 'Sur Name',
type: 'string',
width: 100
},{
index: 'age',
title: 'Age',
type: 'number',
width: 100
}];
}
getData() {
return [
{name: 'Ted', surname: 'Smith', company: 'Electrical Systems', age: 30},
{name: 'Ed', surname: 'Johnson', company: 'Energy and Oil', age: 35},
{name: 'Sam', surname: 'Williams', company: 'Airbus', age: 38},
{name: 'Alexander', surname: 'Brown', company: 'Renault', age: 24},
{name: 'Nicholas', surname: 'Miller', company: 'Adobe', age: 33}
];
}
getEvents() {
return [{
init: this.onGridInit
}];
}
onGridInit = (grid) => {
setTimeout(function(){
grid.setTitle('New Title');
}, 1000);
}
}
export default App;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment