From b15f3ac3b0792db08151f65cb41a160184ebd1bc Mon Sep 17 00:00:00 2001 From: Tanner Linsley Date: Wed, 15 Feb 2017 09:55:42 -0700 Subject: [PATCH] Added "noData" component Fixes #78 --- .storybook/config.js | 2 + README.md | 2 + src/index.js | 16 +++++++- src/index.styl | 12 ++++++ stories/NoDataText.js | 92 +++++++++++++++++++++++++++++++++++++++++++ stories/Simple.js | 7 ---- 6 files changed, 123 insertions(+), 8 deletions(-) create mode 100644 stories/NoDataText.js diff --git a/.storybook/config.js b/.storybook/config.js index 6078b96..db4f8cd 100644 --- a/.storybook/config.js +++ b/.storybook/config.js @@ -22,6 +22,7 @@ import PivotingSubComponents from '../stories/PivotingSubComponents.js' import OneHundredKRows from '../stories/OneHundredKRows.js' import FunctionalRendering from '../stories/FunctionalRendering.js' import CustomExpanderPosition from '../stories/CustomExpanderPosition.js' +import NoDataText from '../stories/NoDataText.js' // configure(() => { storiesOf('1. Docs') @@ -49,4 +50,5 @@ configure(() => { .add('100k Rows w/ Pivoting & Sub Components', OneHundredKRows) .add('Functional Rendering', FunctionalRendering) .add('Custom Expander Position', CustomExpanderPosition) + .add('Custom "No Data" Text', NoDataText) }, module) diff --git a/README.md b/README.md index fd22854..27bc490 100644 --- a/README.md +++ b/README.md @@ -187,6 +187,7 @@ These are all of the available props (and their default values) for the main ` ({}), getPaginationProps: () => ({}), getLoadingProps: () => ({}), + getNoDataProps: () => ({}), // Global Column Defaults column: { @@ -209,6 +210,7 @@ These are all of the available props (and their default values) for the main ` - ) + ), + NoDataComponent: _.makeTemplateComponent('rt-noData') } export default React.createClass({ @@ -272,10 +275,12 @@ export default React.createClass({ getTdProps, getPaginationProps, getLoadingProps, + getNoDataProps, showPagination, expanderColumnWidth, manual, loadingText, + noDataText, // State loading, pageSize, @@ -299,6 +304,7 @@ export default React.createClass({ PaginationComponent, LoadingComponent, SubComponent, + NoDataComponent, // Data model resolvedData, allVisibleColumns, @@ -835,6 +841,7 @@ export default React.createClass({ const tBodyProps = _.splitProps(getTbodyProps(finalState, undefined, undefined, this)) const paginationProps = _.splitProps(getPaginationProps(finalState, undefined, undefined, this)) const loadingProps = getLoadingProps(finalState, undefined, undefined, this) + const noDataProps = getNoDataProps(finalState, undefined, undefined, this) return (
)} + {!pageRows.length && ( + + {_.normalizeComponent(noDataText)} + + )} { + 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) + } + }) + + 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' + }] + }] + + return ( +
+
+ 'Oh Noes!'} // Supports functions + // noDataText={() => Oh Noes!} // Supports JSX / React Components + columns={columns} + defaultPageSize={10} + /> +
+
+
+ Tip: Hold shift when sorting to multi-sort! +
+ {() => getCode()} +
+ ) +} + +function getCode () { + return ` +import ReactTable from 'react-table' + +// 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 ( + 'Oh Noes!'} // Supports functions + // noDataText={() => Oh Noes!} // Supports JSX / React Components + columns={columns} + defaultPageSize={10} + /> +) + ` +} diff --git a/stories/Simple.js b/stories/Simple.js index 4d5c06a..67ee1f7 100644 --- a/stories/Simple.js +++ b/stories/Simple.js @@ -40,13 +40,6 @@ export default () => { data={data} columns={columns} defaultPageSize={10} - getTdProps={() => { - return { - onClick: () => { - console.log('clicked') - } - } - }} />