+ )
+ }
}
+
+// Source Code
+const CodeHighlight = require('./components/codeHighlight').default
+const source = require('!raw-loader!./OneHundredKRows')
+
+export default () => (
+
+)
diff --git a/stories/Pivoting.js b/stories/Pivoting.js
index 37d2c4f..bf70f65 100644
--- a/stories/Pivoting.js
+++ b/stories/Pivoting.js
@@ -2,101 +2,72 @@ import React from 'react'
import _ from 'lodash'
import namor from 'namor'
-import CodeHighlight from './components/codeHighlight'
import ReactTable from '../src/index'
-export default () => {
- const data = _.map(_.range(1000), d => {
- return {
- firstName: namor.generate({ words: 1, numLen: 0 }),
- lastName: namor.generate({ words: 1, numLen: 0 }),
- age: Math.floor(Math.random() * 30),
- visits: Math.floor(Math.random() * 100)
- }
- })
-
- const columns = [{
- Header: 'Name',
- columns: [{
- Header: 'First Name',
- accessor: 'firstName'
- }, {
- Header: 'Last Name',
- id: 'lastName',
- accessor: d => d.lastName
- }]
- }, {
- Header: 'Info',
- columns: [{
- Header: 'Age',
- accessor: 'age',
- aggregate: vals => _.round(_.mean(vals)),
- Aggregated: row => {
- return
+class Story extends React.Component {
+ render () {
+ const data = _.map(_.range(1000), d => {
+ return {
+ firstName: namor.generate({ words: 1, numLen: 0 }),
+ lastName: namor.generate({ words: 1, numLen: 0 }),
+ age: Math.floor(Math.random() * 30),
+ visits: Math.floor(Math.random() * 100)
}
+ })
+
+ const columns = [{
+ Header: 'Name',
+ columns: [{
+ Header: 'First Name',
+ accessor: 'firstName'
+ }, {
+ Header: 'Last Name',
+ id: 'lastName',
+ accessor: d => d.lastName
+ }]
}, {
- Header: 'Visits',
- accessor: 'visits',
- aggregate: vals => _.sum(vals)
+ Header: 'Info',
+ columns: [{
+ Header: 'Age',
+ accessor: 'age',
+ aggregate: vals => _.round(_.mean(vals)),
+ Aggregated: row => {
+ return
+ }
+ }, {
+ Header: 'Visits',
+ accessor: 'visits',
+ aggregate: vals => _.sum(vals)
+ }]
}]
- }]
- return (
-
-
-
+ return (
+
+
+
+
+
+
+ Tip: Hold shift when sorting to multi-sort!
+
-
-
- Tip: Hold shift when sorting to multi-sort!
-
-
{() => getCode()}
-
- )
+ )
+ }
}
-function getCode () {
- return `
-const columns = [{
- Header: 'Name',
- columns: [{
- Header: 'First Name',
- accessor: 'firstName'
- }, {
- Header: 'Last Name',
- id: 'lastName',
- accessor: d => d.lastName
- }]
-}, {
- Header: 'Info',
- columns: [{
- Header: 'Age',
- accessor: 'age',
- aggregate: vals => _.round(_.mean(vals)),
- Cell: row => {
- return
{row.aggregated ? \`\${row.value} (avg)\` : row.value}
- }
- }, {
- Header: 'Visits',
- accessor: 'visits',
- aggregate: vals => _.sum(vals)
- }]
-}]
+// Source Code
+const CodeHighlight = require('./components/codeHighlight').default
+const source = require('!raw-loader!./Pivoting')
-return (
-
+export default () => (
+
+
+ {() => source}
+
)
- `
-}
diff --git a/stories/PivotingOptions.js b/stories/PivotingOptions.js
index 6b1132e..1dd2265 100644
--- a/stories/PivotingOptions.js
+++ b/stories/PivotingOptions.js
@@ -2,121 +2,130 @@ import React from 'react'
import _ from 'lodash'
import namor from 'namor'
-import CodeHighlight from './components/codeHighlight'
import ReactTable from '../src/index'
-import source from '!raw-loader!./PivotingOptions'
+class Story extends React.Component {
+ render () {
+ const data = _.map(_.range(1000), d => {
+ return {
+ firstName: namor.generate({words: 1, numLen: 0}),
+ lastName: namor.generate({words: 1, numLen: 0}),
+ age: Math.floor(Math.random() * 30),
+ visits: Math.floor(Math.random() * 100)
+ }
+ })
-export default () => {
- const data = _.map(_.range(1000), d => {
- return {
- firstName: namor.generate({words: 1, numLen: 0}),
- lastName: namor.generate({words: 1, numLen: 0}),
- age: Math.floor(Math.random() * 30),
- visits: Math.floor(Math.random() * 100)
- }
- })
+ const columns = [{
+ Header: 'Name',
+ columns: [{
+ Header: 'First Name',
+ accessor: 'firstName',
+ PivotValue: ({value}) =>
{value}
+ }, {
+ Header: 'Last Name',
+ id: 'lastName',
+ accessor: d => d.lastName,
+ PivotValue: ({value}) =>
{value},
+ Footer: () =>
Pivot Column Footer
+ }]
+ }, {
+ Header: 'Info',
+ columns: [{
+ Header: 'Age',
+ accessor: 'age',
+ aggregate: vals => {
+ return _.round(_.mean(vals))
+ },
+ Aggregated: row =>
{row.value} (avg)
+ }, {
+ Header: 'Visits',
+ accessor: 'visits',
+ aggregate: vals => _.sum(vals),
+ hideFilter: true
+ }]
+ }, {
+ pivot: true,
+ Header: () =>
Overridden Pivot Column Header Group
+ }, {
+ expander: true
+ }]
- const columns = [{
- Header: 'Name',
- columns: [{
- Header: 'First Name',
- accessor: 'firstName',
- PivotValue: ({value}) =>
{value}
+ const subtableColumns = [{
+ Header: 'Name',
+ columns: [{
+ Header: 'First Name',
+ accessor: 'firstName'
+ }, {
+ Header: 'Last Name',
+ id: 'lastName'
+ }]
}, {
- Header: 'Last Name',
- id: 'lastName',
- accessor: d => d.lastName,
- PivotValue: ({value}) =>
{value},
- Footer: () =>
Pivot Column Footer
+ Header: 'Info',
+ columns: [{
+ Header: 'Age',
+ accessor: 'age'
+ }, {
+ Header: 'Visits',
+ accessor: 'visits'
+ }]
}]
- }, {
- Header: 'Info',
- columns: [{
- Header: 'Age',
- accessor: 'age',
- aggregate: vals => {
- return _.round(_.mean(vals))
- },
- Aggregated: row =>
{row.value} (avg)
- }, {
- Header: 'Visits',
- accessor: 'visits',
- aggregate: vals => _.sum(vals),
- hideFilter: true
- }]
- }, {
- pivot: true,
- Header: () =>
Overridden Pivot Column Header Group
- }, {
- expander: true
- }]
- const subtableColumns = [{
- Header: 'Name',
- columns: [{
- Header: 'First Name',
- accessor: 'firstName'
- }, {
- Header: 'Last Name',
- id: 'lastName'
- }]
- }, {
- Header: 'Info',
- columns: [{
- Header: 'Age',
- accessor: 'age'
- }, {
- Header: 'Visits',
- accessor: 'visits'
- }]
- }]
-
- return (
-
-
-
(
- isExpanded ? ➘ : ➙
- )}
- SubComponent={(row) => {
- return (
-
-
You can put any component you want here, even another React Table!
-
-
-
{
- return (
-
- It even has access to the row data:
- {() => JSON.stringify(row, null, 2)}
-
- )
- }}
- />
-
- )
- }}
- />
+ return (
+
+
+
(
+ isExpanded ? ➘ : ➙
+ )}
+ SubComponent={(row) => {
+ return (
+
+
You can put any component you want here, even another React Table!
+
+
+
{
+ return (
+
+ It even has access to the row data:
+ {() => JSON.stringify(row, null, 2)}
+
+ )
+ }}
+ />
+
+ )
+ }}
+ />
+
+
+
+ Tip: Hold shift when sorting to multi-sort!
+
-
-
- Tip: Hold shift when sorting to multi-sort!
-
- {() => source}
-
- )
+ )
+ }
}
+
+// Source Code
+const CodeHighlight = require('./components/codeHighlight').default
+const source = require('!raw-loader!./EditableTable')
+
+export default () => (
+
+
+ {() => source}
+
+)
diff --git a/stories/PivotingSubComponents.js b/stories/PivotingSubComponents.js
index 0fc8b46..5100dc8 100644
--- a/stories/PivotingSubComponents.js
+++ b/stories/PivotingSubComponents.js
@@ -2,153 +2,98 @@ import React from 'react'
import _ from 'lodash'
import namor from 'namor'
-import CodeHighlight from './components/codeHighlight'
import ReactTable from '../src/index'
-export default () => {
- const data = _.map(_.range(1000), d => {
- return {
- firstName: namor.generate({ words: 1, numLen: 0 }),
- lastName: namor.generate({ words: 1, numLen: 0 }),
- age: Math.floor(Math.random() * 30),
- visits: Math.floor(Math.random() * 100)
- }
- })
+class Story extends React.Component {
+ render () {
+ const data = _.map(_.range(1000), d => {
+ return {
+ firstName: namor.generate({ words: 1, numLen: 0 }),
+ lastName: namor.generate({ words: 1, numLen: 0 }),
+ age: Math.floor(Math.random() * 30),
+ visits: Math.floor(Math.random() * 100)
+ }
+ })
- const columns = [{
- Header: 'Name',
- columns: [{
- Header: 'First Name',
- accessor: 'firstName'
+ const columns = [{
+ Header: 'Name',
+ columns: [{
+ Header: 'First Name',
+ accessor: 'firstName'
+ }, {
+ Header: 'Last Name',
+ id: 'lastName',
+ accessor: d => d.lastName
+ }]
}, {
- Header: 'Last Name',
- id: 'lastName',
- accessor: d => d.lastName
+ Header: 'Info',
+ columns: [{
+ Header: 'Age',
+ accessor: 'age',
+ aggregate: vals => _.round(_.mean(vals)),
+ Aggregated: row => {
+ return
{row.value} (avg)
+ },
+ filterMethod: (filter, row) => (filter.value === `${row[filter.id]} (avg)`)
+ }, {
+ Header: 'Visits',
+ accessor: 'visits',
+ aggregate: vals => _.sum(vals),
+ hideFilter: true
+ }]
}]
- }, {
- Header: 'Info',
- columns: [{
- Header: 'Age',
- accessor: 'age',
- aggregate: vals => _.round(_.mean(vals)),
- Aggregated: row => {
- return
{row.value} (avg)
- },
- filterMethod: (filter, row) => (filter.value === `${row[filter.id]} (avg)`)
- }, {
- Header: 'Visits',
- accessor: 'visits',
- aggregate: vals => _.sum(vals),
- hideFilter: true
- }]
- }]
- return (
-
-
-
{
- return (
-
-
You can put any component you want here, even another React Table!
-
-
-
{
- return (
-
- It even has access to the row data:
- {() => JSON.stringify(row, null, 2)}
-
- )
- }}
- />
-
- )
- }}
- />
-
-
-
- Tip: Hold shift when sorting to multi-sort!
-
-
{() => getCode()}
-
- )
-}
-
-function getCode () {
- return `
-const columns = [{
- Header: 'Name',
- columns: [{
- Header: 'First Name',
- accessor: 'firstName'
- }, {
- Header: 'Last Name',
- id: 'lastName',
- accessor: d => d.lastName
- }]
-}, {
- Header: 'Info',
- columns: [{
- Header: 'Age',
- accessor: 'age',
- aggregate: vals => _.round(_.mean(vals)),
- Cell: row => {
- return
{row.aggregated ? \`\${row.value} (avg)\` : row.value}
- },
- filterMethod: (filter, row) => (filter.value == \`\${row[filter.id]} (avg)\`)
- }, {
- Header: 'Visits',
- accessor: 'visits',
- aggregate: vals => _.sum(vals),
- hideFilter: true
- }]
-}]
-
-return (
-
{
- return (
-
-
You can put any component you want here, even another React Table!
-
-
+ return (
+
+
{
return (
-
It even has access to the row data:
-
{() => JSON.stringify(row, null, 2)}
+
You can put any component you want here, even another React Table!
+
+
+
{
+ return (
+
+ It even has access to the row data:
+ {() => JSON.stringify(row, null, 2)}
+
+ )
+ }}
+ />
)
}}
/>
- )
- }}
- />
-)
- `
+
+
+ Tip: Hold shift when sorting to multi-sort!
+
+
+ )
+ }
}
+
+// Source Code
+const CodeHighlight = require('./components/codeHighlight').default
+const source = require('!raw-loader!./PivotingSubComponents')
+
+export default () => (
+
+
+ {() => source}
+
+)
diff --git a/stories/ServerSide.js b/stories/ServerSide.js
index 783c9cb..3854ffb 100644
--- a/stories/ServerSide.js
+++ b/stories/ServerSide.js
@@ -2,7 +2,6 @@ import React from 'react'
import _ from 'lodash'
import namor from 'namor'
-import CodeHighlight from './components/codeHighlight'
import ReactTable from '../src/index'
const rawData = _.map(_.range(3424), d => {
@@ -49,15 +48,16 @@ const requestData = (pageSize, page, sorting, filters) => {
})
}
-const ServerSide = React.createClass({
- getInitialState () {
- // To handle our data server-side, we need a few things in the state to help us out:
- return {
+class Story extends React.Component {
+ constructor () {
+ super()
+ this.state = {
data: [],
pages: null,
loading: true
}
- },
+ this.fetchData = this.fetchData.bind(this)
+ }
fetchData (state, instance) {
// Whenever the table model changes, or the user sorts or changes pages, this method gets called and passed the current table model.
// You can set the `loading` prop of the table to true to use the built-in one or show you're own loading bar if you want.
@@ -72,7 +72,7 @@ const ServerSide = React.createClass({
loading: false
})
})
- },
+ }
render () {
return (
@@ -103,73 +103,18 @@ const ServerSide = React.createClass({
Tip: Hold shift when sorting to multi-sort!
-
{() => getCode()}
)
}
-})
+}
+
+// Source Code
+const CodeHighlight = require('./components/codeHighlight').default
+const source = require('!raw-loader!./ServerSide')
export default () => (
-
+
+
+ {() => source}
+
)
-
-function getCode () {
- return `
-import ReactTable from 'react-table'
-import Axios from 'axios'
-
-export default React.createClass({
- getInitialState () {
- // To handle our data server-side, we need to keep track of our table state
- return {
- data: [],
- pages: null,
- loading: true
- }
- },
- fetchData (state, instance) {
- // Whenever the table model changes (sorting, pagination, etc), this method gets called and passed the current table model.
- // You can set the 'loading' prop of the table to true to use the built-in loading notice, or show you're own loading bar if you want.
- this.setState({loading: true})
- // Request the data from a server however you want! Be sure to send the bits of the table model that it may neeed.
- Axios.post('mysite.com/data', {
- pageSize: state.pageSize,
- page: state.page,
- sorting: state.sorting,
- filters: state.filters
- })
- .then((res) => {
- // Now update your state!
- this.setState({
- data: res.rows,
- pages: res.pages,
- loading: false
- })
- })
- },
- render () {
- return (
- d.lastName
- }, {
- Header: 'Age',
- accessor: 'age'
- }]}
- manual // Forces table not to paginate or sort automatically, so we can handle it server-side
- defaultPageSize={10}
- showFilters={true}
- data={this.state.data} // Set the rows to be displayed
- pages={this.state.pages} // Display the total number of pages
- loading={this.state.loading} // Display the loading overlay when we need it
- onFetchData={this.fetchData} // Request new data when things change
- />
- }
-})
- `
-}
diff --git a/stories/Simple.js b/stories/Simple.js
index 7e0e336..63c24b8 100644
--- a/stories/Simple.js
+++ b/stories/Simple.js
@@ -2,93 +2,68 @@ import React from 'react'
import _ from 'lodash'
import namor from 'namor'
-import CodeHighlight from './components/codeHighlight'
import ReactTable from '../src/index'
-export default () => {
- const data = _.map(_.range(5553), d => {
- return {
- firstName: namor.generate({ words: 1, numLen: 0 }),
- lastName: namor.generate({ words: 1, numLen: 0 }),
- age: Math.floor(Math.random() * 30),
- children: _.map(_.range(10), d => {
- return {
- firstName: namor.generate({ words: 1, numLen: 0 }),
- lastName: namor.generate({ words: 1, numLen: 0 }),
- age: Math.floor(Math.random() * 30)
- }
- })
- }
- })
+class Story extends React.Component {
+ render () {
+ const data = _.map(_.range(5553), d => {
+ return {
+ firstName: namor.generate({ words: 1, numLen: 0 }),
+ lastName: namor.generate({ words: 1, numLen: 0 }),
+ age: Math.floor(Math.random() * 30),
+ children: _.map(_.range(10), d => {
+ return {
+ firstName: namor.generate({ words: 1, numLen: 0 }),
+ lastName: namor.generate({ words: 1, numLen: 0 }),
+ age: Math.floor(Math.random() * 30)
+ }
+ })
+ }
+ })
- const columns = [{
- Header: 'Name',
- columns: [{
- Header: 'First Name',
- accessor: 'firstName'
+ const columns = [{
+ Header: 'Name',
+ columns: [{
+ Header: 'First Name',
+ accessor: 'firstName'
+ }, {
+ Header: 'Last Name',
+ id: 'lastName',
+ accessor: d => d.lastName
+ }]
}, {
- Header: 'Last Name',
- id: 'lastName',
- accessor: d => d.lastName
+ Header: 'Info',
+ columns: [{
+ Header: 'Age',
+ accessor: 'age'
+ }]
}]
- }, {
- Header: 'Info',
- columns: [{
- Header: 'Age',
- accessor: 'age'
- }]
- }]
- return (
-
-
-
+ return (
+
+
+
+
+
+
+ Tip: Hold shift when sorting to multi-sort!
+
-
-
- Tip: Hold shift when sorting to multi-sort!
-
-
{() => getCode()}
-
- )
+ )
+ }
}
-function getCode () {
- return `
-import ReactTable from 'react-table'
+const CodeHighlight = require('./components/codeHighlight').default
+const source = require('!raw-loader!./Simple')
-// Create some column definitions
-const columns = [{
- Header: 'Name',
- columns: [{
- Header: 'First Name',
- accessor: 'firstName'
- }, {
- Header: 'Last Name',
- id: 'lastName',
- accessor: d => d.lastName
- }]
-}, {
- Header: 'Info',
- columns: [{
- Header: 'Age',
- accessor: 'age'
- }]
-}]
-
-// Display your table!
-return (
-
+export default () => (
+
+
+ {() => source}
+
)
- `
-}
diff --git a/stories/SubComponents.js b/stories/SubComponents.js
index 1eae145..0a75e48 100644
--- a/stories/SubComponents.js
+++ b/stories/SubComponents.js
@@ -2,10 +2,9 @@ import React from 'react'
import _ from 'lodash'
import namor from 'namor'
-import CodeHighlight from './components/codeHighlight'
import ReactTable from '../src/index'
-class SubComponents extends React.Component {
+class Story extends React.Component {
constructor (props) {
super(props)
@@ -131,60 +130,15 @@ class SubComponents extends React.Component {
}
})
}
-
- getCode () {
- return `
-const columns = [{
- Header: 'Name',
- columns: [{
- Header: 'First Name',
- accessor: 'firstName'
- }, {
- Header: 'Last Name',
- id: 'lastName',
- accessor: d => d.lastName
- }]
-}, {
- Header: 'Info',
- columns: [{
- Header: 'Age',
- accessor: 'age'
- }]
-}]
-
-export default (
-
{
- return (
-
-
You can put any component you want here, even another React Table!
-
-
-
{
- return (
-
- It even has access to the row data:
- {() => JSON.stringify(row, null, 2)}
-
- )
- }}
- />
-
- )
- }}
- />
-)
- `
- }
}
-export default () =>
+// Source Code
+const CodeHighlight = require('./components/codeHighlight').default
+const source = require('!raw-loader!./SubComponents')
+
+export default () => (
+
+
+ {() => source}
+
+)
diff --git a/stories/SubRows.js b/stories/SubRows.js
index d35bb3f..747a4c4 100644
--- a/stories/SubRows.js
+++ b/stories/SubRows.js
@@ -2,100 +2,76 @@ import React from 'react'
import _ from 'lodash'
import namor from 'namor'
-import CodeHighlight from './components/codeHighlight'
import ReactTable from '../src/index'
-export default () => {
- const data = _.map(_.range(5553), d => {
- const children = _.map(_.range(10), d => {
- const grandChildren = _.map(_.range(10), d => {
+class Story extends React.Component {
+ render () {
+ const data = _.map(_.range(5553), d => {
+ const children = _.map(_.range(10), d => {
+ const grandChildren = _.map(_.range(10), d => {
+ return {
+ age: Math.floor(Math.random() * 30)
+ }
+ })
return {
- age: Math.floor(Math.random() * 30)
+ firstName: namor.generate({ words: 1, numLen: 0 }),
+ age: Math.floor(Math.random() * 30),
+ children: grandChildren
}
})
return {
- firstName: namor.generate({ words: 1, numLen: 0 }),
+ lastName: namor.generate({ words: 1, numLen: 0 }),
+ firstName: children.map(d => d.firstName),
age: Math.floor(Math.random() * 30),
- children: grandChildren
+ children
}
})
- return {
- lastName: namor.generate({ words: 1, numLen: 0 }),
- firstName: children.map(d => d.firstName),
- age: Math.floor(Math.random() * 30),
- children
- }
- })
- const columns = [{
- Header: 'Name',
- columns: [{
- Header: 'First Name',
- accessor: 'firstName',
- expander: true
+ const columns = [{
+ Header: 'Name',
+ columns: [{
+ Header: 'First Name',
+ accessor: 'firstName',
+ expander: true
+ }, {
+ Header: 'Last Name',
+ accessor: 'lastName'
+ }]
}, {
- Header: 'Last Name',
- accessor: 'lastName'
+ Header: 'Info',
+ columns: [{
+ Header: 'Age',
+ accessor: 'age'
+ }]
}]
- }, {
- Header: 'Info',
- columns: [{
- Header: 'Age',
- accessor: 'age'
- }]
- }]
- return (
-
-
-
+ return (
+
+
+
+
+
+
+ Tip: Hold shift when sorting to multi-sort!
+
-
-
- Tip: Hold shift when sorting to multi-sort!
-
-
{() => getCode()}
-
- )
+ )
+ }
}
-function getCode () {
- return `
-import ReactTable from 'react-table'
+// Source Code
+const CodeHighlight = require('./components/codeHighlight').default
+const source = require('!raw-loader!./SubRows')
-// Create some column definitions
-const columns = [{
- Header: 'Name',
- columns: [{
- Header: 'First Name',
- accessor: 'firstName'
- }, {
- Header: 'Last Name',
- id: 'lastName',
- accessor: d => d.lastName
- }]
-}, {
- Header: 'Info',
- columns: [{
- Header: 'Age',
- accessor: 'age'
- }]
-}]
-
-// Display your table!
-return (
-
+export default () => (
+
+
+ {() => source}
+
)
- `
-}