File tree Expand file tree Collapse file tree 1 file changed +18
-6
lines changed Expand file tree Collapse file tree 1 file changed +18
-6
lines changed Original file line number Diff line number Diff line change @@ -80,20 +80,32 @@ const TableView = (props) => {
8080
8181 const handleSort = ( key ) => {
8282 const updatedItems = [ ...items ] ;
83- updatedItems . sort ( function ( a , b ) {
84- return a [ key ] > b [ key ] ? 1 : - 1 ;
85- } ) ;
86- setItems ( updatedItems ) ;
83+
84+ if ( key !== sortKey ) {
85+ setItems ( ascSort ( updatedItems ) ( key ) ) ;
86+ } else {
87+ setItems ( descSort ( updatedItems ) ( key ) ) ;
88+ }
89+
8790 setSortKey ( key === sortKey ? "" : key ) ;
8891 } ;
8992
90- console . table ( sortKey ) ;
93+ const ascSort = ( list ) => ( key ) =>
94+ list . sort ( function ( a , b ) {
95+ return a [ key ] > b [ key ] ? 1 : - 1 ;
96+ } ) ;
97+
98+ const descSort = ( list ) => ( key ) =>
99+ list . sort ( function ( a , b ) {
100+ return a [ key ] > b [ key ] ? - 1 : 1 ;
101+ } ) ;
102+
91103 return (
92104 < div className = { styles . container } >
93105 < div className = "table-view" >
94106 < div className = "search" >
95107 < input
96- placeholder = "Search Name"
108+ placeholder = "Search by Name"
97109 value = { searchQuery }
98110 onChange = { handleSearch }
99111 />
You can’t perform that action at this time.
0 commit comments