-
Notifications
You must be signed in to change notification settings - Fork 357
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
139 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 13 additions & 3 deletions
16
...s/patternfly-4/react-virtualized-extension/src/components/Virtualized/Virtualized.docs.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,24 @@ | ||
import { AutoSizer } from '@patternfly/react-virtualized-extension'; | ||
import { | ||
AutoSizer, | ||
VirtualizedBody, | ||
VirtualizedBodyWrapper, | ||
VirtualizedRowWrapper | ||
} from '@patternfly/react-virtualized-extension'; | ||
import AutoSizerExample from './examples/AutoSizerExample'; | ||
import VirtualizedExample from './examples/VirtualizedExample'; | ||
import SortableExample from './examples/SortableExample'; | ||
|
||
export default { | ||
title: 'Virtualized', | ||
components: { | ||
AutoSizer | ||
AutoSizer, | ||
VirtualizedBody, | ||
VirtualizedBodyWrapper, | ||
VirtualizedRowWrapper | ||
}, | ||
examples: [ | ||
{ component: AutoSizerExample, title: 'Simple AutoSizer Example' }, | ||
{ component: VirtualizedExample, title: 'Simple Virtualized Example' } | ||
{ component: VirtualizedExample, title: 'Simple Virtualized Example' }, | ||
{ component: SortableExample, title: 'Sortable Virtualized Example' } | ||
] | ||
}; |
72 changes: 72 additions & 0 deletions
72
...nfly-4/react-virtualized-extension/src/components/Virtualized/examples/SortableExample.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import React from 'react'; | ||
import { Table, TableHeader, sortable, SortByDirection } from '@patternfly/react-table'; | ||
import { | ||
VirtualizedBody, | ||
VirtualizedBodyWrapper, | ||
VirtualizedRowWrapper | ||
} from '@patternfly/react-virtualized-extension'; | ||
import './sample.css'; | ||
|
||
class SortableExample extends React.Component { | ||
static title = 'Simple Table'; | ||
constructor(props) { | ||
super(props); | ||
|
||
this.tableBody = React.createRef(); | ||
|
||
const rows = []; | ||
for (let i = 0; i < 100; i++) { | ||
rows.push({ | ||
id: i, | ||
cells: [`one-${i}`, `two-${i}`, `three-${i}`, `four-${i}`, `five-${i}`] | ||
}); | ||
} | ||
this.state = { | ||
columns: [ | ||
{ title: 'Repositories', transforms: [sortable], props: { style: { width: '20%' } } }, | ||
{ title: 'Branches', props: { style: { width: '20%' } } }, | ||
{ title: 'Pull requests', transforms: [sortable], props: { style: { width: '20%' } } }, | ||
{ title: 'Workspaces', props: { style: { width: '20%' } } }, | ||
{ title: 'Last Commit', props: { style: { width: '20%' } } } | ||
], | ||
rows, | ||
sortBy: {} | ||
}; | ||
this.onSort = this.onSort.bind(this); | ||
} | ||
|
||
onSort(_event, index, direction) { | ||
const sortedRows = this.state.rows.sort( | ||
(a, b) => (a.cells[index] < b.cells[index] ? -1 : a.cells[index] > b.cells[index] ? 1 : 0) | ||
); | ||
this.tableBody.current.scrollTo(0); | ||
this.setState({ | ||
sortBy: { | ||
index, | ||
direction | ||
}, | ||
rows: direction === SortByDirection.asc ? sortedRows : sortedRows.reverse() | ||
}); | ||
} | ||
|
||
render() { | ||
const { columns, rows, sortBy } = this.state; | ||
|
||
return ( | ||
<Table | ||
caption="Sortable Virtualized Table" | ||
cells={columns} | ||
rows={rows} | ||
bodyWrapper={VirtualizedBodyWrapper} | ||
rowWrapper={VirtualizedRowWrapper} | ||
sortBy={sortBy} | ||
onSort={this.onSort} | ||
> | ||
<TableHeader /> | ||
<VirtualizedBody height={400} rowKey="id" tableBody={this.tableBody} /> | ||
</Table> | ||
); | ||
} | ||
} | ||
|
||
export default SortableExample; |