-
-
Notifications
You must be signed in to change notification settings - Fork 305
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
malo
committed
Nov 21, 2022
1 parent
2659e6c
commit b82acd7
Showing
5 changed files
with
121 additions
and
107 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,107 +1,43 @@ | ||
import * as React from 'react' | ||
import { GroupedTableVirtuoso, GroupedTableVirtuosoHandle } from '../src/' | ||
import React, { useMemo } from 'react' | ||
import { GroupedTableVirtuoso } from '../src/' | ||
|
||
export default function App() { | ||
const ref = React.useRef<GroupedTableVirtuosoHandle>(null) | ||
return ( | ||
<> | ||
<GroupedTableVirtuoso | ||
ref={ref} | ||
components={{ | ||
EmptyPlaceholder: () => { | ||
return ( | ||
<tbody> | ||
<tr> | ||
<td>Empty</td> | ||
</tr> | ||
</tbody> | ||
) | ||
}, | ||
}} | ||
groupCounts={Array.from({ length: 100 }).fill(10) as number[]} | ||
style={{ height: 700 }} | ||
fixedHeaderContent={() => { | ||
return ( | ||
<tr style={{ background: 'white' }}> | ||
<th key={1} style={{ height: 150, border: '1px solid black', background: 'white' }}> | ||
TH 1 | ||
</th> | ||
<th key={2} style={{ height: 150, border: '1px solid black', background: 'white' }}> | ||
TH meh | ||
</th> | ||
</tr> | ||
) | ||
}} | ||
fixedFooterContent={() => { | ||
return ( | ||
<tr style={{ background: 'white' }}> | ||
<th key={1} style={{ height: 150, border: '1px solid black', background: 'white' }}> | ||
Footer TH 1 | ||
</th> | ||
<th key={2} style={{ height: 150, border: '1px solid black', background: 'white' }}> | ||
Footer TH meh | ||
</th> | ||
</tr> | ||
) | ||
}} | ||
itemContent={(index) => { | ||
return ( | ||
<> | ||
<td style={{ height: 21 }}>{index}Cell 1</td> | ||
<td style={{ height: 21 }}>Cell 2</td> | ||
</> | ||
) | ||
}} | ||
groupContent={(index) => { | ||
return ( | ||
<> | ||
<td style={{ height: 21 }}>Group {index}</td> | ||
<td style={{ height: 21 }}>Meh</td> | ||
</> | ||
) | ||
}} | ||
/> | ||
<button | ||
onClick={() => | ||
ref.current.scrollToIndex({ | ||
index: 900, | ||
align: 'start', | ||
}) | ||
} | ||
> | ||
scroll 900 start | ||
</button> | ||
<button | ||
onClick={() => | ||
ref.current.scrollToIndex({ | ||
index: 900, | ||
align: 'end', | ||
}) | ||
} | ||
> | ||
scroll 900 end | ||
</button> | ||
const groupCounts = useMemo(() => { | ||
return Array(1000).fill(10) as number[] | ||
}, []) | ||
|
||
<button | ||
onClick={() => | ||
ref.current.scrollToIndex({ | ||
index: 900, | ||
align: 'center', | ||
}) | ||
} | ||
> | ||
scroll 900 center | ||
</button> | ||
<button | ||
onClick={() => | ||
ref.current.scrollIntoView({ | ||
index: 50, | ||
}) | ||
} | ||
> | ||
scroll 50 into view | ||
</button> | ||
<p>Buttons should align 900 correctly </p> | ||
</> | ||
return ( | ||
<GroupedTableVirtuoso | ||
groupCounts={groupCounts} | ||
style={{ height: 700 }} | ||
fixedHeaderContent={() => { | ||
return ( | ||
<tr style={{ background: 'white', textAlign: 'left' }}> | ||
<th key={1} style={{ width: '140px' }}> | ||
Item index | ||
</th> | ||
<th key={2} style={{ width: '140px' }}> | ||
Greetings | ||
</th> | ||
</tr> | ||
) | ||
}} | ||
itemContent={(index) => { | ||
return ( | ||
<> | ||
<td style={{ height: 21 }}>{index}</td> | ||
<td style={{ height: 21 }}>Hello</td> | ||
</> | ||
) | ||
}} | ||
groupContent={(index) => { | ||
return ( | ||
<> | ||
<td style={{ height: 21, background: 'white' }}>Group {index}</td> | ||
<td style={{ height: 21, background: 'white' }} /> | ||
</> | ||
) | ||
}} | ||
/> | ||
) | ||
} |
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,56 @@ | ||
--- | ||
id: grouped-table | ||
title: Grouped Table | ||
sidebar_label: Grouped Table | ||
slug: /grouped-table/ | ||
--- | ||
|
||
The example below shows a simple table grouping mode. | ||
|
||
```jsx live | ||
import { GroupedTableVirtuoso } from 'react-virtuoso' | ||
import { useMemo, useRef } from 'react' | ||
|
||
export default function App() { | ||
const ref = useRef() | ||
|
||
const groupCounts = useMemo(() => { | ||
return Array(1000).fill(10) | ||
}, []) | ||
|
||
return ( | ||
<GroupedTableVirtuoso | ||
groupCounts={groupCounts} | ||
style={{ height: 400 }} | ||
fixedHeaderContent={() => { | ||
return ( | ||
<tr style={{ background: 'white', textAlign: 'left' }}> | ||
<th key={1} style={{ width: '140px' }}> | ||
Item index | ||
</th> | ||
<th key={2} style={{ width: '140px' }}> | ||
Greetings | ||
</th> | ||
</tr> | ||
) | ||
}} | ||
itemContent={(index) => { | ||
return ( | ||
<> | ||
<td style={{ height: 21 }}>{index}</td> | ||
<td style={{ height: 21 }}>Hello</td> | ||
</> | ||
) | ||
}} | ||
groupContent={(index) => { | ||
return ( | ||
<> | ||
<td style={{ height: 21, background: 'white' }}>Group {index}</td> | ||
<td style={{ height: 21, background: 'white' }} /> | ||
</> | ||
) | ||
}} | ||
/> | ||
) | ||
} | ||
``` |
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
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