File tree Expand file tree Collapse file tree 4 files changed +161
-0
lines changed
apps/docs/content/components/table Expand file tree Collapse file tree 4 files changed +161
-0
lines changed Original file line number Diff line number Diff line change 1+ import type { Selection } from "@heroui/react" ;
2+
3+ import React from "react" ;
4+ import {
5+ Table ,
6+ TableHeader ,
7+ TableColumn ,
8+ TableBody ,
9+ TableRow ,
10+ TableCell ,
11+ getKeyValue ,
12+ } from "@heroui/react" ;
13+
14+ const rows = [
15+ {
16+ key : "1" ,
17+ name : "Tony Reichert" ,
18+ role : "CEO" ,
19+ status : "Active" ,
20+ } ,
21+ {
22+ key : "2" ,
23+ name : "Zoey Lang" ,
24+ role : "Technical Lead" ,
25+ status : "Paused" ,
26+ } ,
27+ {
28+ key : "3" ,
29+ name : "Jane Fisher" ,
30+ role : "Senior Developer" ,
31+ status : "Active" ,
32+ } ,
33+ {
34+ key : "4" ,
35+ name : "William Howard" ,
36+ role : "Community Manager" ,
37+ status : "Vacation" ,
38+ } ,
39+ ] ;
40+
41+ const columns = [
42+ {
43+ key : "name" ,
44+ label : "NAME" ,
45+ } ,
46+ {
47+ key : "role" ,
48+ label : "ROLE" ,
49+ } ,
50+ {
51+ key : "status" ,
52+ label : "STATUS" ,
53+ } ,
54+ ] ;
55+
56+ export default function App ( ) {
57+ const [ selectedKeys , setSelectedKeys ] = React . useState < Selection > ( new Set ( [ "2" ] ) ) ;
58+
59+ return (
60+ < Table
61+ aria-label = "Controlled table example with dynamic content"
62+ selectedKeys = { selectedKeys }
63+ selectionMode = "multiple"
64+ onSelectionChange = { setSelectedKeys }
65+ >
66+ < TableHeader columns = { columns } >
67+ { ( column ) => < TableColumn key = { column . key } > { column . label } </ TableColumn > }
68+ </ TableHeader >
69+ < TableBody items = { rows } >
70+ { ( item ) => (
71+ < TableRow key = { item . key } >
72+ { ( columnKey ) => < TableCell > { getKeyValue ( item , columnKey ) } </ TableCell > }
73+ </ TableRow >
74+ ) }
75+ </ TableBody >
76+ </ Table >
77+ ) ;
78+ }
Original file line number Diff line number Diff line change 11import App from "./controlled-selection.raw.jsx?raw" ;
2+ import AppTs from "./controlled-selection.raw.tsx?raw" ;
23
34const react = {
45 "/App.jsx" : App ,
6+ "/App.tsx" : AppTs ,
57} ;
68
79export default {
Original file line number Diff line number Diff line change 1+ import type { Selection } from "@heroui/react" ;
2+
3+ import React from "react" ;
4+ import {
5+ Table ,
6+ TableHeader ,
7+ TableColumn ,
8+ TableBody ,
9+ TableRow ,
10+ TableCell ,
11+ getKeyValue ,
12+ } from "@heroui/react" ;
13+
14+ const rows = [
15+ {
16+ key : "1" ,
17+ name : "Tony Reichert" ,
18+ role : "CEO" ,
19+ status : "Active" ,
20+ } ,
21+ {
22+ key : "2" ,
23+ name : "Zoey Lang" ,
24+ role : "Technical Lead" ,
25+ status : "Paused" ,
26+ } ,
27+ {
28+ key : "3" ,
29+ name : "Jane Fisher" ,
30+ role : "Senior Developer" ,
31+ status : "Active" ,
32+ } ,
33+ {
34+ key : "4" ,
35+ name : "William Howard" ,
36+ role : "Community Manager" ,
37+ status : "Vacation" ,
38+ } ,
39+ ] ;
40+
41+ const columns = [
42+ {
43+ key : "name" ,
44+ label : "NAME" ,
45+ } ,
46+ {
47+ key : "role" ,
48+ label : "ROLE" ,
49+ } ,
50+ {
51+ key : "status" ,
52+ label : "STATUS" ,
53+ } ,
54+ ] ;
55+
56+ export default function App ( ) {
57+ const [ selectedKeys , setSelectedKeys ] = React . useState < Selection > ( new Set ( [ "2" ] ) ) ;
58+
59+ return (
60+ < Table
61+ aria-label = "Controlled table example with dynamic content"
62+ disabledKeys = { [ "3" , "4" ] }
63+ selectedKeys = { selectedKeys }
64+ selectionMode = "multiple"
65+ onSelectionChange = { setSelectedKeys }
66+ >
67+ < TableHeader columns = { columns } >
68+ { ( column ) => < TableColumn key = { column . key } > { column . label } </ TableColumn > }
69+ </ TableHeader >
70+ < TableBody items = { rows } >
71+ { ( item ) => (
72+ < TableRow key = { item . key } >
73+ { ( columnKey ) => < TableCell > { getKeyValue ( item , columnKey ) } </ TableCell > }
74+ </ TableRow >
75+ ) }
76+ </ TableBody >
77+ </ Table >
78+ ) ;
79+ }
Original file line number Diff line number Diff line change 11import App from "./disabled-rows.raw.jsx?raw" ;
2+ import AppTs from "./disabled-rows.raw.tsx?raw" ;
23
34const react = {
45 "/App.jsx" : App ,
6+ "/App.tsx" : AppTs ,
57} ;
68
79export default {
You can’t perform that action at this time.
0 commit comments