Skip to content

Commit 9d82cee

Browse files
committed
Better vertical responsiveness & Fixed Header example
1 parent db1edf1 commit 9d82cee

File tree

3 files changed

+115
-11
lines changed

3 files changed

+115
-11
lines changed

docs/src/App.js

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,34 +25,35 @@ import Filtering from './stories/Filtering.js'
2525
import ControlledTable from './stories/ControlledTable.js'
2626
import PivotingOptions from './stories/PivotingOptions.js'
2727
import EditableTable from './stories/EditableTable.js'
28+
import FixedHeader from './stories/FixedHeader.js'
2829

2930
export default class App extends React.Component {
30-
render () {
31+
render() {
3132
return (
3233
<ReactStory
3334
style={{
3435
display: 'block',
3536
width: '100%',
3637
height: '100%'
3738
}}
38-
pathPrefix='story/'
39-
StoryWrapper={(props) => (
39+
pathPrefix="story/"
40+
StoryWrapper={props => (
4041
<defaultProps.StoryWrapper
4142
css={{
4243
padding: 0
4344
}}
4445
>
4546
<a
46-
href='//github.com/tannerlinsley/react-table'
47+
href="//github.com/tannerlinsley/react-table"
4748
style={{
4849
display: 'block',
4950
textAlign: 'center',
5051
borderBottom: 'solid 3px #cccccc'
5152
}}
5253
>
5354
<img
54-
src='//npmcdn.com/react-table/media/Banner.png'
55-
alt='React Table Logo'
55+
src="//npmcdn.com/react-table/media/Banner.png"
56+
alt="React Table Logo"
5657
style={{
5758
width: '100px'
5859
}}
@@ -69,24 +70,37 @@ export default class App extends React.Component {
6970
stories={[
7071
{ name: 'Readme', component: Readme },
7172
{ name: 'Simple Table', component: Simple },
72-
{ name: 'Cell Renderers & Custom Components', component: CellRenderers },
73+
{
74+
name: 'Cell Renderers & Custom Components',
75+
component: CellRenderers
76+
},
7377
{ name: 'Default Sorting', component: DefaultSorting },
7478
{ name: 'Custom Sorting', component: CustomSorting },
7579
{ name: 'Custom Column Widths', component: CustomWidths },
7680
{ name: 'Custom Component Props', component: CustomComponentProps },
7781
{ name: 'Server-side Data', component: ServerSide },
7882
{ name: 'Sub Components', component: SubComponents },
7983
{ name: 'Pivoting & Aggregation', component: Pivoting },
80-
{ name: 'Pivoting & Aggregation w/ Sub Components', component: PivotingSubComponents },
81-
{ name: '100k Rows w/ Pivoting & Sub Components', component: OneHundredKRows },
84+
{
85+
name: 'Pivoting & Aggregation w/ Sub Components',
86+
component: PivotingSubComponents
87+
},
88+
{
89+
name: '100k Rows w/ Pivoting & Sub Components',
90+
component: OneHundredKRows
91+
},
8292
{ name: 'Pivoting Options', component: PivotingOptions },
8393
{ name: 'Functional Rendering', component: FunctionalRendering },
84-
{ name: 'Custom Expander Position', component: CustomExpanderPosition },
94+
{
95+
name: 'Custom Expander Position',
96+
component: CustomExpanderPosition
97+
},
8598
{ name: 'Custom "No Data" Text', component: NoDataText },
8699
{ name: 'Footers', component: Footers },
87100
{ name: 'Custom Filtering', component: Filtering },
88101
{ name: 'Controlled Component', component: ControlledTable },
89-
{ name: 'Editable Table', component: EditableTable }
102+
{ name: 'Editable Table', component: EditableTable },
103+
{ name: 'Fixed Header w/ Vertical Scroll', component: FixedHeader }
90104
]}
91105
/>
92106
)

docs/src/stories/FixedHeader.js

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/* eslint-disable import/no-webpack-loader-syntax */
2+
import React from 'react'
3+
import _ from 'lodash'
4+
import namor from 'namor'
5+
6+
import ReactTable from '../../../lib/index'
7+
8+
class Story extends React.PureComponent {
9+
render() {
10+
const data = _.map(_.range(5553), d => {
11+
return {
12+
firstName: namor.generate({ words: 1, numLen: 0 }),
13+
lastName: namor.generate({ words: 1, numLen: 0 }),
14+
age: Math.floor(Math.random() * 30),
15+
children: _.map(_.range(10), d => {
16+
return {
17+
firstName: namor.generate({ words: 1, numLen: 0 }),
18+
lastName: namor.generate({ words: 1, numLen: 0 }),
19+
age: Math.floor(Math.random() * 30)
20+
}
21+
})
22+
}
23+
})
24+
25+
const columns = [
26+
{
27+
Header: 'Name',
28+
columns: [
29+
{
30+
Header: 'First Name',
31+
accessor: 'firstName'
32+
},
33+
{
34+
Header: 'Last Name',
35+
id: 'lastName',
36+
accessor: d => d.lastName
37+
}
38+
]
39+
},
40+
{
41+
Header: 'Info',
42+
columns: [
43+
{
44+
Header: 'Age',
45+
accessor: 'age'
46+
}
47+
]
48+
}
49+
]
50+
51+
return (
52+
<div>
53+
<div className="table-wrap">
54+
<ReactTable
55+
className="-striped -highlight"
56+
data={data}
57+
columns={columns}
58+
defaultPageSize={20}
59+
style={{
60+
height: '400px' // This will force the table body to overflow and scroll, since there is not enough room
61+
}}
62+
/>
63+
</div>
64+
<div style={{ textAlign: 'center' }}>
65+
<br />
66+
<em>Tip: Hold shift when sorting to multi-sort!</em>
67+
</div>
68+
</div>
69+
)
70+
}
71+
}
72+
73+
const CodeHighlight = require('./components/codeHighlight').default
74+
const source = require('!raw!./Simple')
75+
76+
export default () => (
77+
<div>
78+
<Story />
79+
<CodeHighlight>{() => source}</CodeHighlight>
80+
</div>
81+
)

src/index.styl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@ $expandSize = 7px
44

55
.ReactTable
66
position:relative
7+
display: flex
8+
flex-direction: column
79
border: 1px solid alpha(black, .1)
810
*
911
box-sizing: border-box
1012
.rt-table
13+
flex: 1
1114
display: flex
1215
flex-direction: column
1316
align-items: stretch
@@ -16,6 +19,7 @@ $expandSize = 7px
1619
overflow: auto
1720

1821
.rt-thead
22+
flex: 1 0 auto
1923
display: flex
2024
flex-direction: column
2125
-webkit-user-select: none;
@@ -91,8 +95,10 @@ $expandSize = 7px
9195
margin-top: -10px
9296

9397
.rt-tbody
98+
flex: 99999 1 auto
9499
display: flex
95100
flex-direction: column
101+
overflow: auto
96102
// z-index:0
97103
.rt-tr-group
98104
border-bottom: solid 1px alpha(black, .05)
@@ -105,10 +111,12 @@ $expandSize = 7px
105111
.rt-expandable
106112
cursor: pointer
107113
.rt-tr-group
114+
flex: 1 0 auto
108115
display: flex
109116
flex-direction: column
110117
align-items: stretch
111118
.rt-tr
119+
flex: 1 0 auto
112120
display: inline-flex
113121
.rt-th
114122
.rt-td
@@ -191,6 +199,7 @@ $expandSize = 7px
191199
appearance:none
192200
display:block
193201
width:100%
202+
height:100%
194203
border: 0
195204
border-radius: 3px
196205
padding: 6px

0 commit comments

Comments
 (0)