react-toolbox/components/table/readme.md

61 lines
2.3 KiB
Markdown
Raw Normal View History

2015-11-04 06:15:27 +03:00
# Table
2015-11-14 12:26:50 +03:00
The Table component is an enhanced version of the standard HTML `<table>`. A data-table consists of rows and columns of well-formatted data, presented with appropriate user interaction capabilities. This component uses a solid typed model, helping you to create formatted formated cells. These cells can be editable if you subscribe to `onChange` method who dispatch then new source with each change.
2015-11-04 06:15:27 +03:00
<!-- example -->
```jsx
import Table from 'react-toolbox/lib/table';
2015-11-04 06:15:27 +03:00
const UserModel = {
2015-11-14 12:26:50 +03:00
name: {type: String},
twitter: {type: String},
birthdate: {type: Date},
cats: {type: Number},
dogs: {type: Number},
2015-11-04 06:15:27 +03:00
active: {type: Boolean}
};
const users = [
2015-11-14 12:26:50 +03:00
{name: 'Javi Jimenez', twitter: '@soyjavi', birthdate: new Date(1980, 3, 11), cats: 1},
2015-11-04 06:20:02 +03:00
{name: 'Javi Velasco', twitter: '@javivelasco', birthdate: new Date(1987, 1, 1), dogs: 1, active: true}
2015-11-04 06:15:27 +03:00
];
2015-11-14 12:26:50 +03:00
class TableTest extends React.Component {
state = { selected: [], source: users };
handleChange = (row, key, value) => {
const source = this.state.source;
source[row][key] = value;
this.setState({source});
};
handleSelect = (selected) => {
this.setState({selected});
};
render () {
return (
<Table
model={UserModel}
onChange={this.handleChange}
onSelect={this.handleSelect}
selected={this.state.selected}
source={this.state.source}
/>
);
}
}
2015-11-04 06:15:27 +03:00
```
## Properties
| Name | Type | Default | Description|
|:-----|:-----|:-----|:-----|
2015-11-14 12:26:50 +03:00
| `className` | `String` | `''` | Sets a custom class to style the Component.|
2015-11-04 06:15:27 +03:00
| `heading` | `Bool` | `true` | If true, component will show a heading using model field names.|
2015-11-14 12:26:50 +03:00
| `model` | `Object` | | Object describing the data model that represents each object in the `source`.|
| `onChange` | `Function` | | Callback function that is fired when an item in a row changes. If set, rows are editable. |
| `onSelect` | `Function` | | Callback function invoked when the row selection changes.|
| `selected` | `Array` | | Array of indexes of the items in the source that should appear as selected.|
| `source` | `Array` | | Array of objects representing each item to show.|