From 2300fa99ffed0fc58ad144b23f193e95888ce31d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Let=C3=ADcia=20Camara?= Date: Mon, 29 Oct 2018 19:32:25 -0300 Subject: [PATCH] Fix ambassador's telegram sort --- src/components/EnhancedTable.js | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/components/EnhancedTable.js b/src/components/EnhancedTable.js index 56f7cb8..c2eb106 100644 --- a/src/components/EnhancedTable.js +++ b/src/components/EnhancedTable.js @@ -93,8 +93,26 @@ class EnhancedTable extends Component { const data = order === 'desc' - ? this.state.data.sort((a, b) => (b[orderBy].toLowerCase() < a[orderBy].toLowerCase() ? -1 : 1)) - : this.state.data.sort((a, b) => (a[orderBy].toLowerCase() < b[orderBy].toLowerCase() ? -1 : 1)); + ? this.state.data.sort((a, b) => { + console.log(a[orderBy]); + console.log(b[orderBy]); + if(a[orderBy].hasOwnProperty('searchText')){ + a[orderBy] = a[orderBy].searchText; + } + if(b[orderBy].hasOwnProperty('searchText')){ + b[orderBy] = b[orderBy].searchText; + } + return b[orderBy].toLowerCase() < a[orderBy].toLowerCase() ? -1 : 1; + }) + : this.state.data.sort((a, b) => { + if(a[orderBy].hasOwnProperty('searchText')){ + a[orderBy] = a[orderBy].searchText; + } + if(b[orderBy].hasOwnProperty('searchText')){ + b[orderBy] = b[orderBy].searchText; + } + return (a[orderBy].toLowerCase() < b[orderBy].toLowerCase() ? -1 : 1); + }); this.setState({ data, order, orderBy }); };