Skip to content

Commit 5d60141

Browse files
author
Kamran Asif
committed
more examples
1 parent 0c08d9d commit 5d60141

File tree

3 files changed

+142
-0
lines changed

3 files changed

+142
-0
lines changed

Diff for: examples/PaginationExample.js

+135
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
/**
2+
* This file provided by Facebook is for non-commercial testing and evaluation
3+
* purposes only. Facebook reserves all rights not expressly granted.
4+
*
5+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
6+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
7+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
8+
* FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
9+
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
10+
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
11+
*/
12+
13+
"use strict";
14+
15+
var ExampleImage = require('./helpers/ExampleImage');
16+
var FakeObjectDataListStore = require('./helpers/FakeObjectDataListStore');
17+
var FixedDataTable = require('fixed-data-table');
18+
var React = require('react');
19+
20+
const {Table, Column, Cell} = FixedDataTable;
21+
22+
const TextCell = ({rowIndex, data, col, ...props}) => {
23+
var rowObject = data.getObjectAt(rowIndex);
24+
return (
25+
<Cell {...props}>
26+
{rowObject ? rowObject[col] : 'pending'}
27+
</Cell>
28+
);
29+
};
30+
31+
class PagedData {
32+
constructor(callback) {
33+
this._dataList = new FakeObjectDataListStore(2000);
34+
this._end = 50;
35+
this._pending = false;
36+
this._callback = callback;
37+
}
38+
39+
getSize() {
40+
return 2000;
41+
}
42+
43+
fetchRange(end) {
44+
if (this._pending) {
45+
return;
46+
}
47+
48+
this._pending = true;
49+
return new Promise((resolve) => setTimeout(resolve, 1000))
50+
.then(() => {
51+
this._pending = false;
52+
this._end = end;
53+
this._callback(end)
54+
});
55+
}
56+
57+
getObjectAt(index) {
58+
if (index >= this._end) {
59+
this.fetchRange(Math.min(2000, index + 50));
60+
return null;
61+
}
62+
return this._dataList.getObjectAt(index);
63+
}
64+
}
65+
66+
class PaginationExample extends React.Component {
67+
constructor(props) {
68+
super(props);
69+
70+
this._updateData = this._updateData.bind(this);
71+
this.state = {
72+
pagedData: new PagedData(this._updateData),
73+
end: 50
74+
};
75+
}
76+
77+
//Just need to force a refresh
78+
_updateData(end) {
79+
this.setState({
80+
end: end
81+
});
82+
}
83+
84+
render() {
85+
var {pagedData} = this.state;
86+
87+
return (
88+
<div>
89+
<Table
90+
rowHeight={50}
91+
rowsCount={pagedData.getSize()}
92+
headerHeight={50}
93+
width={1000}
94+
height={500}
95+
{...this.props}>
96+
<Column
97+
header={<Cell></Cell>}
98+
cell={({rowIndex}) => (<Cell>{rowIndex}</Cell>)}
99+
fixed={true}
100+
width={50}
101+
/>
102+
<Column
103+
header={<Cell>First Name</Cell>}
104+
cell={<TextCell data={pagedData} col="firstName" />}
105+
fixed={true}
106+
width={100}
107+
/>
108+
<Column
109+
header={<Cell>Last Name</Cell>}
110+
cell={<TextCell data={pagedData} col="lastName" />}
111+
fixed={true}
112+
width={100}
113+
/>
114+
<Column
115+
header={<Cell>City</Cell>}
116+
cell={<TextCell data={pagedData} col="city" />}
117+
width={100}
118+
/>
119+
<Column
120+
header={<Cell>Street</Cell>}
121+
cell={<TextCell data={pagedData} col="street" />}
122+
width={200}
123+
/>
124+
<Column
125+
header={<Cell>Zip Code</Cell>}
126+
cell={<TextCell data={pagedData} col="zipCode" />}
127+
width={200}
128+
/>
129+
</Table>
130+
</div>
131+
);
132+
}
133+
}
134+
135+
module.exports = PaginationExample;

Diff for: site/Constants.js

+6
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,12 @@ exports.ExamplePages = {
7676
title: 'Column Groups',
7777
description: 'Table with column groupings.',
7878
},
79+
PAGINATION_EXAMPLE: {
80+
location: 'example-pagination.html',
81+
file: EXAMPLES_LOCATION_BASE + 'PaginationExample.js',
82+
title: 'Pagination',
83+
description: 'A table example that pages in data as the user scrolls. We fake this by having a promise that resolves after a few milliseconds',
84+
},
7985
FILTER_EXAMPLE: {
8086
location: 'example-filter.html',
8187
file: EXAMPLES_LOCATION_BASE + 'FilterExample.js',

Diff for: site/examples/ExamplesPage.js

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ var EXAMPLE_COMPONENTS = {
4343
[ExamplePages.COLLAPSE_EXAMPLE.location]: require('../../examples/CollapseExample'),
4444
[ExamplePages.FLEXGROW_EXAMPLE.location]: require('../../examples/FlexGrowExample'),
4545
[ExamplePages.COLUMN_GROUPS_EXAMPLE.location]: require('../../examples/ColumnGroupsExample'),
46+
[ExamplePages.PAGINATION_EXAMPLE.location]: require('../../examples/PaginationExample'),
4647
[ExamplePages.FILTER_EXAMPLE.location]: require('../../examples/FilterExample'),
4748
[ExamplePages.SORT_EXAMPLE.location]: require('../../examples/SortExample'),
4849
};

0 commit comments

Comments
 (0)