-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6384 from MBelniak/master
Feat: Stateful TreeTable
- Loading branch information
Showing
8 changed files
with
498 additions
and
24 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
import { DocSectionCode } from '@/components/doc/common/docsectioncode'; | ||
import { DocSectionText } from '@/components/doc/common/docsectiontext'; | ||
import { Column } from '@/components/lib/column/Column'; | ||
import { TreeTable } from '@/components/lib/treetable/TreeTable'; | ||
import { useEffect, useState } from 'react'; | ||
import { NodeService } from '../../../service/NodeService'; | ||
|
||
export function StatefulDoc(props) { | ||
const [nodes, setNodes] = useState([]); | ||
|
||
useEffect(() => { | ||
NodeService.getTreeTableNodes().then((data) => setNodes(data)); | ||
}, []); // eslint-disable-line react-hooks/exhaustive-deps | ||
|
||
const code = { | ||
basic: ` | ||
<TreeTable value={nodes} stateKey={'tree-table-state-demo-session'} stateStorage={'session'}> | ||
<Column field="name" header="Name" expander filter filterPlaceholder="Filter by name"></Column> | ||
<Column field="size" header="Size" filter filterPlaceholder="Filter by size"></Column> | ||
<Column field="type" header="Type" filter filterPlaceholder="Filter by type"></Column> | ||
</TreeTable> | ||
`, | ||
javascript: ` | ||
import React, { useState, useEffect } from 'react'; | ||
import { TreeTable } from 'primereact/treetable'; | ||
import { Column } from 'primereact/column'; | ||
import { NodeService } from './service/NodeService'; | ||
export default function StatefulDemo() { | ||
const [nodes, setNodes] = useState([]); | ||
useEffect(() => { | ||
NodeService.getTreeTableNodes().then((data) => setNodes(data)); | ||
}, []); | ||
return ( | ||
<div className="card"> | ||
<TreeTable value={nodes} tableStyle={{ minWidth: '50rem' }} stateKey={'tree-table-state-demo-session'} stateStorage={'session'} | ||
paginator rows={5} rowsPerPageOptions={[5, 10, 25]}> | ||
<Column field="name" header="Name" expander filter filterPlaceholder="Filter by name"></Column> | ||
<Column field="size" header="Size" filter filterPlaceholder="Filter by size"></Column> | ||
<Column field="type" header="Type" filter filterPlaceholder="Filter by type"></Column> | ||
</TreeTable> | ||
</div> | ||
) | ||
} | ||
`, | ||
typescript: ` | ||
import React, { useState, useEffect } from 'react'; | ||
import { TreeTable } from 'primereact/treetable'; | ||
import { Column } from 'primereact/column'; | ||
import { TreeNode } from 'primereact/treenode'; | ||
import { NodeService } from './service/NodeService'; | ||
export default function StatefulDemo() { | ||
const [nodes, setNodes] = useState<TreeNode[]>([]); | ||
useEffect(() => { | ||
NodeService.getTreeTableNodes().then((data) => setNodes(data)); | ||
}, []); | ||
return ( | ||
<div className="card"> | ||
<TreeTable value={nodes} tableStyle={{ minWidth: '50rem' }} stateKey={'tree-table-state-demo-session'} stateStorage={'session'} | ||
paginator rows={5} rowsPerPageOptions={[5, 10, 25]}> | ||
<Column field="name" header="Name" expander filter filterPlaceholder="Filter by name"></Column> | ||
<Column field="size" header="Size" filter filterPlaceholder="Filter by size"></Column> | ||
<Column field="type" header="Type" filter filterPlaceholder="Filter by type"></Column> | ||
</TreeTable> | ||
</div> | ||
) | ||
} | ||
`, | ||
data: ` | ||
{ | ||
key: '0', | ||
label: 'Documents', | ||
data: 'Documents Folder', | ||
icon: 'pi pi-fw pi-inbox', | ||
children: [ | ||
{ | ||
key: '0-0', | ||
label: 'Work', | ||
data: 'Work Folder', | ||
icon: 'pi pi-fw pi-cog', | ||
children: [ | ||
{ key: '0-0-0', label: 'Expenses.doc', icon: 'pi pi-fw pi-file', data: 'Expenses Document' }, | ||
{ key: '0-0-1', label: 'Resume.doc', icon: 'pi pi-fw pi-file', data: 'Resume Document' } | ||
] | ||
}, | ||
{ | ||
key: '0-1', | ||
label: 'Home', | ||
data: 'Home Folder', | ||
icon: 'pi pi-fw pi-home', | ||
children: [{ key: '0-1-0', label: 'Invoices.txt', icon: 'pi pi-fw pi-file', data: 'Invoices for this month' }] | ||
} | ||
] | ||
}, | ||
... | ||
` | ||
}; | ||
|
||
return ( | ||
<> | ||
<DocSectionText {...props}> | ||
<p>Stateful table allows keeping the state such as page, sort and filtering either at local storage or session storage so that when the page is visited again, table would render the data using the last settings.</p> | ||
<p> | ||
Change the state of the table e.g paginate or expand rows, navigate away and then return to this table again to test this feature. The setting is set as <i>session</i> with the <i>stateStorage</i> property so that Table retains | ||
the state until the browser is closed. Other alternative is <i>local</i> referring to <i>localStorage</i> for an extended lifetime. | ||
</p> | ||
</DocSectionText> | ||
<div className="card"> | ||
<TreeTable value={nodes} tableStyle={{ minWidth: '50rem' }} stateKey={'tree-table-state-demo-session'} stateStorage={'session'} paginator rows={5} rowsPerPageOptions={[5, 10, 25]}> | ||
<Column field="name" header="Name" expander filter filterPlaceholder="Filter by name" sortable /> | ||
<Column field="size" header="Size" filter filterPlaceholder="Filter by size" sortable /> | ||
<Column field="type" header="Type" filter filterPlaceholder="Filter by type" sortable /> | ||
</TreeTable> | ||
</div> | ||
<DocSectionCode code={code} service={['NodeService']} /> | ||
</> | ||
); | ||
} |
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
Oops, something went wrong.