From 4fe15375b31e28cdd970a23d286a7ee5a835ef29 Mon Sep 17 00:00:00 2001 From: geek Date: Fri, 25 Aug 2017 18:50:54 +0900 Subject: [PATCH] sort --- .../react/component/SortTableHeaderRow.tsx | 18 ++++++++++-------- .../history/react/components/HistoryList.tsx | 14 +++++++++++--- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/ts/@overflow/commons/react/component/SortTableHeaderRow.tsx b/src/ts/@overflow/commons/react/component/SortTableHeaderRow.tsx index 7b8c028..516bd8f 100644 --- a/src/ts/@overflow/commons/react/component/SortTableHeaderRow.tsx +++ b/src/ts/@overflow/commons/react/component/SortTableHeaderRow.tsx @@ -6,12 +6,13 @@ import { export interface Props { - columnList?: string[]; + columnMap?: Map; onHeaderColumnClick?(col:string, direction: string): void; } export interface State { column: string; + colvalue: string; direction: 'ascending' | 'descending'; } @@ -22,6 +23,7 @@ export class SortTableHeaderRow extends React.Component { super(props, context); this.state = { column: null, + colvalue: null, direction: null, }; } @@ -37,14 +39,12 @@ export class SortTableHeaderRow extends React.Component { private renderCell = (): (JSX.Element | JSX.Element[]) => { let arr = []; let idx:number = 0; - - for (let colValue of this.props.columnList) { - + this.props.columnMap.forEach((val:string, key:string ) => { arr.push( {colValue}); - } + sorted={this.state.column === key ? this.state.direction : null} + onClick={this.handleColumnSort(key)}>{key}); + }); return arr; } @@ -57,11 +57,13 @@ export class SortTableHeaderRow extends React.Component { }); } else { this.setState({ + column: col, direction: this.state.direction === 'ascending' ? 'descending' : 'ascending', }); } - this.props.onHeaderColumnClick(this.state.column, this.state.direction); + console.log(this.state.column); + this.props.onHeaderColumnClick(this.props.columnMap.get(this.state.column), this.state.direction); } diff --git a/src/ts/@overflow/history/react/components/HistoryList.tsx b/src/ts/@overflow/history/react/components/HistoryList.tsx index 0f4fd97..c410d47 100644 --- a/src/ts/@overflow/history/react/components/HistoryList.tsx +++ b/src/ts/@overflow/history/react/components/HistoryList.tsx @@ -118,16 +118,24 @@ export class HistoryList extends React.Component { } private handleSort = (col:string, direction:string):void => { - console.log(col + 'direction:' + direction); + console.log(col + ' || direction:' + direction); } public render(): JSX.Element { - let cols:string[] = ['No.', 'Probe', 'Type', 'Message', 'Created At', 'Created By']; + // let cols:string[] = ['No.', 'Probe', 'Type', 'Message', 'Created At', 'Created By']; + let colsmap:Map = new Map(); + colsmap.set('No.', 'id'); + colsmap.set('Probe', 'probe.id'); + colsmap.set('Type', ' type.id'); + colsmap.set('Message', 'message'); + colsmap.set('Created At', 'createDate'); + colsmap.set('Created By', 'member.id'); + let historyList: JSX.Element = ( - + {/**/} {/*No.*/} {/*Probe*/}