@@ -19,34 +19,42 @@ const mapDispatchToProps = {
1919const connector = connect ( mapStateToProps , mapDispatchToProps ) ;
2020interface Props extends ConnectedProps < typeof connector > { }
2121
22+ const sort = ( a , b ) : number => {
23+ return isNaN ( a ) && isNaN ( b ) ? ( a || '' ) . localeCompare ( b || '' ) : a - b ;
24+ } ;
25+
2226export const _ProductList = ( props : Props ) => {
2327 const history = useHistory ( ) ;
2428
2529 const { products, getProducts, clearProduct } = props ;
2630
27- const columns = [
31+ const columns : any = [
2832 {
2933 title : 'Preview' ,
3034 dataIndex : 'image_url' ,
3135 render : ( image_url , row ) => renderImgProduct ( image_url , row ) ,
32- key : 'image_url' ,
3336 } ,
3437 {
3538 title : 'Name' ,
3639 dataIndex : 'name' ,
40+ sorter : ( a , b ) => {
41+ return a . name . localeCompare ( b . name ) ;
42+ } ,
43+ sortDirections : [ 'descend' , 'ascend' ] ,
3744 render : ( name , row ) => showProduct ( name , row ) ,
38- key : 'name' ,
3945 } ,
4046 {
4147 title : 'Brand' ,
4248 dataIndex : 'brand' ,
43- key : 'brand' ,
49+ sorter : ( a , b ) => {
50+ return a . brand . localeCompare ( b . brand ) ;
51+ } ,
52+ defaultSortOrder : 'descend' ,
4453 } ,
4554 ] ;
4655 const showProduct = ( name , row ) => {
4756 return (
4857 < Link
49- key = { row . id }
5058 to = { `${ PATH . PRODUCTS } /${ row . id } ` }
5159 style = { { textTransform : 'uppercase' } }
5260 >
@@ -57,7 +65,7 @@ export const _ProductList = (props: Props) => {
5765 const renderImgProduct = ( image_url , row ) => {
5866 if ( row . id ) {
5967 return (
60- < Link to = { `${ PATH . PRODUCTS } /${ row . id } ` } key = { row . id } >
68+ < Link to = { `${ PATH . PRODUCTS } /${ row . id } ` } >
6169 < Image src = { image_url } alt = "Image_sp" style = { { maxWidth : '100px' } } />
6270 </ Link >
6371 ) ;
0 commit comments