Skip to content

Commit

Permalink
Documentation!
Browse files Browse the repository at this point in the history
Added:
- Getting started guide
- v0.6 migration guide
- `Cell` API documentation
- Added v0.5 API docs
  • Loading branch information
pieterv committed Nov 11, 2015
1 parent f9be64d commit a285a6f
Show file tree
Hide file tree
Showing 11 changed files with 1,044 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ __build__
__site__
__site_prerender__
internal
docs
docs/api
dist
*.swp
5 changes: 5 additions & 0 deletions build_helpers/buildAPIDocs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ var FILES_TO_READ = [
path: path.join(PROJECT_ROOT, 'src/FixedDataTableColumnGroupNew.react.js'),
name: 'ColumnGroup',
markdownFileName: 'ColumnGroupAPI.md'
},
{
path: path.join(PROJECT_ROOT, 'src/FixedDataTableCellDefault.react.js'),
name: 'Cell',
markdownFileName: 'CellAPI.md'
}
];

Expand Down
4 changes: 2 additions & 2 deletions build_helpers/buildSiteIndexPages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ function getAllLocations(pages) {
return locations;
}

var locations = Constants.ALL_PAGES.reduce(function(allPage, pages) {
return [].concat(allPage, getAllLocations(pages));
var locations = Constants.ALL_PAGES.reduce(function(allPages, pages) {
return [].concat(allPages, getAllLocations(pages));
}, []);

locations.forEach(function(fileName) {
Expand Down
195 changes: 195 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
Getting Started
===============

The easiest way to start using on FixedDataTable is to install it via npm:

```shell
npm install react --save
npm install fixed-data-table --save
```

If your using a standard build system such as [`browserify`](http://browserify.org/) or [`webpack`](https://webpack.github.io/) it can then be required directly:
```
const React = require('react');
const {Table, Column, Cell} = require('fixed-data-table');
```

For layout and styling the default stylesheet will need to be added: `fixed-data-table/dist/fixed-data-table.min.css`.

## Create your `Table`
Setting up your table can be done via the `Table` component. To be able to handle large amounts of data the table only renders the parts that are visible to the user, in order to calculate this a static `width`, `height`, `rowsCount` and `rowHeight` are required:

```javascript
const React = require('react');
const {Table} = require('fixed-data-table');

class MyTable extends React.Component {
render() {
return (
<Table
rowsCount={100}
rowHeight={50}
width={1000}
height={500}>
// TODO: Add columns
</Table>
);
}
}
```

## Create your `Column`s
For each column that needs to be displayed a `Column` config with 2 important props are required. The `width` of the column and the `cell` content to render. The `Cell` component can wrap any content to provide default table styles and centering.

```javascript
const React = require('react');
const {Table, Column, Cell} = require('fixed-data-table');

class MyTable extends React.Component {
render() {
return (
<Table
rowsCount={100}
rowHeight={50}
width={1000}
height={500}>
<Column
cell={<Cell>Basic content</Cell>}
width={200}
/>
</Table>
);
}
}
```

## Provide Custom Data
Typically you will want to render custom data per row, let's add some data to our table and add a header to the column.

```javascript
const React = require('react');
const {Table, Column, Cell} = require('fixed-data-table');

class MyTable extends React.Component {
constructor(props) {
super(props);

this.state = {
myTableData: [
{name: 'Rylan'},
{name: 'Amelia'},
{name: 'Estevan'},
{name: 'Florence'},
{name: 'Tressa'},
],
};
}

render() {
return (
<Table
rowsCount={this.state.myTableData.length}
rowHeight={50}
headerHeight={50}
width={1000}
height={500}>
<Column
header={<Cell>Name</Cell>}
cell={props => (
<Cell {...props}>
{this.state.myTableData[props.rowIndex].name}
</Cell>
)}
width={200}
/>
</Table>
);
}
}
```

Instead of providing a static `cell` we can use a function for our `cell`, this function will be passed the `rowIndex` plus the `width` and `height` of the cell. By using the `rowIndex` and we can get different data from `this.state.myTableData` for each cell.

## Create Reusable Cells

With larger table setups you will want to reuse the `cell` render functions. To do this you can create your own React Component for each unique `Cell`. Let's add another column that displays emails with links.

```javascript
const React = require('react');
const {Table, Column, Cell} = require('fixed-data-table');

class MyTextCell extends React.Component {
render() {
const {rowIndex, field, data, ...props} = this.props;
return (
<Cell {...props}>
{data[rowIndex][field]}
</Cell>
);
}
}

class MyLinkCell extends React.Component {
render() {
const {rowIndex, field, data, ...props} = this.props;
const link = data[rowIndex][field];
return (
<Cell {...props}>
<a href={link}>{link}</a>
</Cell>
);
}
}

class MyTable extends React.Component {
constructor(props) {
super(props);

this.state = {
myTableData: [
{name: 'Rylan', email: '[email protected]'},
{name: 'Amelia', email: '[email protected]'},
{name: 'Estevan', email: '[email protected]'},
{name: 'Florence', email: '[email protected]'},
{name: 'Tressa', email: '[email protected]'},
],
};
}

render() {
return (
<Table
rowsCount={this.state.myTableData.length}
rowHeight={50}
headerHeight={50}
width={1000}
height={500}>
<Column
header={<Cell>Name</Cell>}
cell={
<MyTextCell
data={this.state.myTableData}
field="name"
/>
}
width={200}
/>
<Column
header={<Cell>Email</Cell>}
cell={
<MyLinkCell
data={this.state.myTableData}
field="email"
/>
}
width={200}
/>
</Table>
);
}
}
```

## Next Steps

The FixedDataTable has many more options, for more information see the [examples section](http://facebook.github.io/fixed-data-table/example-object-data.html) or the [API docs](http://facebook.github.io/fixed-data-table/api-table.html).
Loading

0 comments on commit a285a6f

Please sign in to comment.