Skip to content

Commit

Permalink
Add TableState demo
Browse files Browse the repository at this point in the history
  • Loading branch information
mertsincan committed Feb 2, 2019
1 parent c206273 commit 9d73834
Show file tree
Hide file tree
Showing 5 changed files with 226 additions and 11 deletions.
2 changes: 2 additions & 0 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ import { DataTableResponsiveDemo } from './showcase/datatable/DataTableResponsiv
import { DataTableEditDemo } from './showcase/datatable/DataTableEditDemo';
import { DataTableRowGroupDemo } from './showcase/datatable/DataTableRowGroupDemo';
import { DataTableStyleDemo } from './showcase/datatable/DataTableStyleDemo';
import { DataTableStateDemo } from './showcase/datatable/DataTableStateDemo';
import { OrderListDemo } from './showcase/orderlist/OrderListDemo';
import { PickListDemo } from './showcase/picklist/PickListDemo';
import { FullCalendarDemo } from './showcase/fullcalendar/FullCalendarDemo';
Expand Down Expand Up @@ -364,6 +365,7 @@ export class App extends Component {
<Route path="/datatable/rowgroup" component={DataTableRowGroupDemo} />
<Route path="/datatable/crud" component={DataTableCrudDemo} />
<Route path="/datatable/style" component={DataTableStyleDemo} />
<Route path="/datatable/state" component={DataTableStateDemo} />
<Route path="/orderlist" component={OrderListDemo} />
<Route path="/picklist" component={PickListDemo} />
<Route path="/fullcalendar" component={FullCalendarDemo} />
Expand Down
1 change: 0 additions & 1 deletion src/sass/App.scss
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,6 @@ body {
td {
padding: 8px 14px;
border: 1px solid #d4e1e3;
word-break: break-word;
}

tr{
Expand Down
70 changes: 60 additions & 10 deletions src/showcase/datatable/DataTableDemo.js
Original file line number Diff line number Diff line change
Expand Up @@ -1577,6 +1577,42 @@ export class DataTableLazyDemo extends Component {
`}
</CodeHighlight>

<h3>TableState</h3>
<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 its last settings. Enabling state is easy as defining a unique <i>stateKey</i>, the storage to keep the state is defined with the <i>stateStorage</i> property that accepts session for sessionStorage and local for localStorage.
Currently following features are supported by TableState; paging, sorting, filtering, column resizing, column reordering, row expansion and row selection.</p>

<CodeHighlight className="language-javascript">
{`
export class DataTableStateDemo extends Component {
constructor() {
super();
this.state = {};
this.carservice = new CarService();
}
componentDidMount() {
this.carservice.getCarsSmall().then(data => this.setState({cars: data}));
}
render() {
return (
<DataTable value={this.state.cars} selectionMode="multiple" resizableColumns={true}
selection={this.state.selectedCars} onSelectionChange={e => this.setState({selectedCars: e.value})}
paginator={true} rows={10} stateKey="tablestatedemo-session">
<Column field="vin" header="Vin" sortable={true} filter={true}/>
<Column field="year" header="Year" sortable={true} filter={true}/>
<Column field="brand" header="Brand" sortable={true} filter={true}/>
<Column field="color" header="Color" sortable={true} filter={true}/>
</DataTable>
);
}
}
`}
</CodeHighlight>

<h3>Responsive</h3>
<p>DataTable columns are displayed as stacked in responsive mode if the screen size becomes smaller than a certain breakpoint value. This feature is enabled by setting responsive to true.</p>
<CodeHighlight className="language-jsx">
Expand Down Expand Up @@ -1672,7 +1708,7 @@ export class DataTableLazyDemo extends Component {
<tr>
<td>paginatorTemplate</td>
<td>string</td>
<td>FirstPageLink PrevPageLink PageLinks NextPageLink LastPageLink RowsPerPageDropdown</td>
<td>FirstPageLink PrevPageLink PageLinks <br /> NextPageLink LastPageLink RowsPerPageDropdown</td>
<td>Template of the paginator.</td>
</tr>
<tr>
Expand Down Expand Up @@ -1702,7 +1738,7 @@ export class DataTableLazyDemo extends Component {
<tr>
<td>currentPageReportTemplate</td>
<td>string</td>
<td>(&123;currentPage&125; of &123;totalPages&125;)</td>
<td>(&#123;currentPage&#125; of &#123;totalPages&#125;)</td>
<td>Template of the current page report element.</td>
</tr>
<tr>
Expand Down Expand Up @@ -1787,7 +1823,7 @@ export class DataTableLazyDemo extends Component {
<td>compareSelectionBy</td>
<td>string</td>
<td>deepEquals</td>
<td>Algorithm to define if a row is selected, valid values are "equals" that compares by reference and "deepEquals" that compares all fields.</td>
<td>Algorithm to define if a row is selected, valid values are "equals" that compares by reference and <br/> "deepEquals" that compares all fields.</td>
</tr>
<tr>
<td>dataKey</td>
Expand All @@ -1799,32 +1835,34 @@ export class DataTableLazyDemo extends Component {
<td>metaKeySelection</td>
<td>boolean</td>
<td>true</td>
<td>Defines whether metaKey is requred or not for the selection. When true metaKey needs to be pressed to select or unselect an item and when set to false selection of each item
<td>Defines whether metaKey is requred or not for the selection. <br/>
When true metaKey needs to be pressed to select or unselect an item and <br/>
when set to false selection of each item
can be toggled individually. On touch enabled devices, metaKeySelection is turned off automatically.</td>
</tr>
<tr>
<td>headerColumnGroup</td>
<td>ColumnGroup</td>
<td>null</td>
<td>ColumnCroup component for header.</td>
<td>ColumnGroup component for header.</td>
</tr>
<tr>
<td>footerColumnGroup</td>
<td>ColumnGroup</td>
<td>null</td>
<td>ColumnCroup component for footer.</td>
<td>ColumnGroup component for footer.</td>
</tr>
<tr>
<td>frozenHeaderColumnGroup</td>
<td>ColumnGroup</td>
<td>null</td>
<td>ColumnCroup component for header of frozen columns.</td>
<td>ColumnGroup component for header of frozen columns.</td>
</tr>
<tr>
<td>frozenFooterColumnGroup</td>
<td>ColumnGroup</td>
<td>null</td>
<td>ColumnCroup component for footer of frozen columns.</td>
<td>ColumnGroup component for footer of frozen columns.</td>
</tr>
<tr>
<td>rowExpansionTemplate</td>
Expand Down Expand Up @@ -1854,7 +1892,7 @@ export class DataTableLazyDemo extends Component {
<td>columnResizeMode</td>
<td>string</td>
<td>fit</td>
<td>Defines whether the overall table width should change on column resize, valid values are "fit" and "expand".</td>
<td>Defines whether the overall table width should change on column resize, <br/> valid values are "fit" and "expand".</td>
</tr>
<tr>
<td>reorderableColumns</td>
Expand Down Expand Up @@ -1944,7 +1982,7 @@ export class DataTableLazyDemo extends Component {
<td>rowClassName</td>
<td>function</td>
<td>null</td>
<td>Function that takes the row data and returns an object in "&#123;'styleclass' : condition&#125;" format to define a classname for a particular now.</td>
<td>Function that takes the row data and <br/> returns an object in "&#123;'styleclass' : condition&#125;" format to define a classname for a particular now.</td>
</tr>
<tr>
<td>rowGroupHeaderTemplate</td>
Expand Down Expand Up @@ -1976,6 +2014,18 @@ export class DataTableLazyDemo extends Component {
<td>null</td>
<td>Index of the element in tabbing order.</td>
</tr>
<tr>
<td>stateKey</td>
<td>string</td>
<td>null</td>
<td>Unique identifier of a stateful table to use in state storage.</td>
</tr>
<tr>
<td>stateStorage</td>
<td>string</td>
<td>session</td>
<td>Defines where a stateful table keeps its state, <br/> valid values are "session" for sessionStorage and "local" for localStorage.</td>
</tr>
</tbody>
</table>
</div>
Expand Down
163 changes: 163 additions & 0 deletions src/showcase/datatable/DataTableStateDemo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
import React, { Component } from 'react';
import {DataTable} from '../../components/datatable/DataTable';
import {Column} from '../../components/column/Column';
import {CarService} from '../service/CarService';
import {DataTableSubmenu} from '../../showcase/datatable/DataTableSubmenu';
import {TabView,TabPanel} from '../../components/tabview/TabView';
import {CodeHighlight} from '../codehighlight/CodeHighlight';

export class DataTableStateDemo extends Component {

constructor() {
super();
this.state = {};
this.carservice = new CarService();
}

componentDidMount() {
this.carservice.getCarsMedium().then(data => this.setState({cars1: data, cars2: data}));
}

displaySelection(data) {
if(!data || data.length === 0) {
return <div style={{textAlign: 'left'}}>No Selection</div>;
}
else {
if(data instanceof Array)
return <ul style={{textAlign: 'left', margin: 0}}>{data.map((car,i) => <li key={car.vin}>{car.vin + ' - ' + car.year + ' - ' + car.brand + ' - ' + car.color}</li>)}</ul>;
else
return <div style={{textAlign: 'left'}}>Selected Car: {data.vin + ' - ' + data.year + ' - ' + data.brand + ' - ' + data.color}</div>
}
}

render() {
return (
<div>
<DataTableSubmenu />

<div className="content-section introduction">
<div className="feature-intro">
<h1>DataTable - State</h1>
<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 its last settings.</p>
</div>
</div>

<div className="content-section implementation">
<h3>Session Storage</h3>
<DataTable value={this.state.cars1} selectionMode="multiple" resizableColumns={true} footer={this.displaySelection(this.state.selectedCars1)}
selection={this.state.selectedCars1} onSelectionChange={e => this.setState({selectedCars1: e.value})} paginator={true} rows={10} stateKey="tablestatedemo-session">
<Column field="vin" header="Vin" sortable={true} filter={true}/>
<Column field="year" header="Year" sortable={true} filter={true}/>
<Column field="brand" header="Brand" sortable={true} filter={true}/>
<Column field="color" header="Color" sortable={true} filter={true}/>
</DataTable>

<h3>Local Storage</h3>
<DataTable value={this.state.cars2} selectionMode="multiple" resizableColumns={true} footer={this.displaySelection(this.state.selectedCars2)}
selection={this.state.selectedCars2} onSelectionChange={e => this.setState({selectedCars2: e.value})} paginator={true} rows={10} stateKey="tablestatedemo-local">
<Column field="vin" header="Vin" sortable={true} filter={true}/>
<Column field="year" header="Year" sortable={true} filter={true}/>
<Column field="brand" header="Brand" sortable={true} filter={true}/>
<Column field="color" header="Color" sortable={true} filter={true}/>
</DataTable>

</div>

<DataTableStateDemoDoc></DataTableStateDemoDoc>
</div>
);
}
}

export class DataTableStateDemoDoc extends Component {

shouldComponentUpdate(){
return false;
}

render() {
return (
<div className="content-section documentation">
<TabView>
<TabPanel header="Source">
<CodeHighlight className="language-javascript">
{`
import React, { Component } from 'react';
import {DataTable} from '../../components/datatable/DataTable';
import {Column} from '../../components/column/Column';
import {CarService} from '../service/CarService';
import {DataTableSubmenu} from '../../showcase/datatable/DataTableSubmenu';
import {TabView,TabPanel} from '../../components/tabview/TabView';
import {CodeHighlight} from '../codehighlight/CodeHighlight';
export class DataTableStateDemo extends Component {
constructor() {
super();
this.state = {};
this.carservice = new CarService();
}
componentDidMount() {
this.carservice.getCarsMedium().then(data => this.setState({cars1: data, cars2: data}));
}
displaySelection(data) {
if(!data || data.length === 0) {
return <div style={{textAlign: 'left'}}>No Selection</div>;
}
else {
if(data instanceof Array)
return <ul style={{textAlign: 'left', margin: 0}}>{data.map((car,i) => <li key={car.vin}>{car.vin + ' - ' + car.year + ' - ' + car.brand + ' - ' + car.color}</li>)}</ul>;
else
return <div style={{textAlign: 'left'}}>Selected Car: {data.vin + ' - ' + data.year + ' - ' + data.brand + ' - ' + data.color}</div>
}
}
render() {
return (
<div>
<DataTableSubmenu />
<div className="content-section introduction">
<div className="feature-intro">
<h1>DataTable - State</h1>
<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 its last settings.</p>
</div>
</div>
<div className="content-section implementation">
<h3>Session Storage</h3>
<DataTable value={this.state.cars1} selectionMode="multiple" resizableColumns={true} footer={this.displaySelection(this.state.selectedCars1)}
selection={this.state.selectedCars1} onSelectionChange={e => this.setState({selectedCars1: e.value})} paginator={true} rows={10} stateKey="tablestatedemo-session">
<Column field="vin" header="Vin" sortable={true} filter={true}/>
<Column field="year" header="Year" sortable={true} filter={true}/>
<Column field="brand" header="Brand" sortable={true} filter={true}/>
<Column field="color" header="Color" sortable={true} filter={true}/>
</DataTable>
<h3>Local Storage</h3>
<DataTable value={this.state.cars2} selectionMode="multiple" resizableColumns={true} footer={this.displaySelection(this.state.selectedCars2)}
selection={this.state.selectedCars2} onSelectionChange={e => this.setState({selectedCars2: e.value})} paginator={true} rows={10} stateKey="tablestatedemo-local">
<Column field="vin" header="Vin" sortable={true} filter={true}/>
<Column field="year" header="Year" sortable={true} filter={true}/>
<Column field="brand" header="Brand" sortable={true} filter={true}/>
<Column field="color" header="Color" sortable={true} filter={true}/>
</DataTable>
</div>
</div>
);
}
}
`}
</CodeHighlight>
</TabPanel>
</TabView>
</div>
)
}
}
1 change: 1 addition & 0 deletions src/showcase/datatable/DataTableSubmenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export class DataTableSubmenu extends Component {
<li><Link to="/datatable/export">&#9679; Export</Link></li>
<li><Link to="/datatable/contextmenu">&#9679; ContextMenu</Link></li>
<li><Link to="/datatable/crud">&#9679; Crud</Link></li>
<li><Link to="/datatable/state">&#9679; State</Link></li>
</ul>
</div>
);
Expand Down

0 comments on commit 9d73834

Please sign in to comment.