Skip to content
Snippets Groups Projects
Commit 5923b712 authored by Lukáš Kratochvíl's avatar Lukáš Kratochvíl
Browse files

fix: BrowseDirectors - birthdate sorting, indentation

parent 017e2d08
No related branches found
No related tags found
No related merge requests found
import { Space, Card, Table } from "antd"; import { Space, Table } from "antd";
import React from "react"
import { Link } from "react-router-dom"; import { Link } from "react-router-dom";
import { DirectorIO } from "./Preview" import { DirectorIO } from "./Preview"
...@@ -30,71 +29,59 @@ const exampleDirectors: DirectorIO[] = [{ ...@@ -30,71 +29,59 @@ const exampleDirectors: DirectorIO[] = [{
}, },
] ]
export const BrowseDirectors = () => { export const BrowseDirectors = () => {
const columns = [
const columns = [ {
{ title: "Name",
title: "Name", dataIndex: "name",
dataIndex: "name", sorter: (a: DirectorIO, b: DirectorIO) => {
sorter: (a:DirectorIO, b:DirectorIO) => { //surname has higher priority
//surname has higher priority if (a.surname < b.surname) {return -1;}
if(a.surname < b.surname){return -1;} if (a.surname > b.surname) {return 1;}
if(a.surname > b.surname){return 1;}
if(a.name < b.name){return -1;}
if(a.name > b.name){return 1;}
return 0;
},
render: (text: string, record: DirectorIO) => (
<Link to={`/director/${record.id}`}>
<a>{record.name} {record.surname}</a>
</Link>
),
},
{ if (a.name < b.name) {return -1;}
title: "Birthdate", if (a.name > b.name) {return 1;}
className: "birthdate", return 0;
dataIndex: "birthdate", },
sorter: (a:DirectorIO, b:DirectorIO) => { render: (text: string, record: DirectorIO) => (
const first = a.birthdate.split('.').reverse(); <Link to={`/director/${record.id}`}>
const second = b.birthdate.split('.').reverse(); <a>{record.name} {record.surname}</a>
if(first[0] > second[0]){return 1 ;} </Link>
if(first[0] < second[0]){return -1 ;} ),
},
if(first[1] > second[1]){return 1 ;} {
if(first[1] < second[1]){return -1 ;} title: "Birthdate",
className: "birthdate",
if(first[2] > second[2]){return 1 ;} dataIndex: "birthdate",
if(first[2] < second[2]){return -1 ;} sorter: (a: DirectorIO, b: DirectorIO) => {
return 0;}, const first = a?.birthdate?.split('.').reverse();
} const second = b?.birthdate?.split('.').reverse();
];
if (first === undefined && second === undefined) { return 0; }
if (first === undefined) { return 1;}
if (second === undefined) { return -1;}
if (first[0] > second[0]) {return 1;}
if (first[0] < second[0]) {return -1;}
if (first[1] > second[1]) {return 1;}
if (first[1] < second[1]) {return -1;}
if (first[2] > second[2]) {return 1;}
if (first[2] < second[2]) {return -1;}
return 0;
},
}
];
return ( return (
<div className="browse-container"> <div className="browse-container">
<Space direction="vertical" size="middle" style={{ padding: "4%" }}> <Space direction="vertical" size="middle" style={{ padding: "4%" }}>
<Table <Table
columns={columns} columns={columns}
dataSource={exampleDirectors} dataSource={exampleDirectors}
> />
</Space>
</Table> </div>
);
</Space> }
</div>
);
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment