Skip to content

Commit

Permalink
feat: able to sort users now
Browse files Browse the repository at this point in the history
  • Loading branch information
songquanpeng committed Nov 6, 2022
1 parent ba9d139 commit a2fd920
Showing 1 changed file with 54 additions and 5 deletions.
59 changes: 54 additions & 5 deletions web/src/components/UsersTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,20 @@ const UsersTable = () => {
setSearchKeyword(value);
};

const sortUser = (key) => {
if (users.length === 0) return;
setLoading(true);
let sortedUsers = [...users];
sortedUsers.sort((a, b) => {
return ('' + a[key]).localeCompare(b[key]);
});
if (sortedUsers[0].id === users[0].id) {
sortedUsers.reverse();
}
setUsers(sortedUsers);
setLoading(false);
};

return (
<>
<Form onSubmit={searchUsers}>
Expand All @@ -108,11 +122,46 @@ const UsersTable = () => {
<Table basic>
<Table.Header>
<Table.Row>
<Table.HeaderCell>用户名</Table.HeaderCell>
<Table.HeaderCell>显示名称</Table.HeaderCell>
<Table.HeaderCell>邮箱地址</Table.HeaderCell>
<Table.HeaderCell>用户角色</Table.HeaderCell>
<Table.HeaderCell>状态</Table.HeaderCell>
<Table.HeaderCell
style={{ cursor: 'pointer' }}
onClick={() => {
sortUser('username');
}}
>
用户名
</Table.HeaderCell>
<Table.HeaderCell
style={{ cursor: 'pointer' }}
onClick={() => {
sortUser('display_name');
}}
>
显示名称
</Table.HeaderCell>
<Table.HeaderCell
style={{ cursor: 'pointer' }}
onClick={() => {
sortUser('email');
}}
>
邮箱地址
</Table.HeaderCell>
<Table.HeaderCell
style={{ cursor: 'pointer' }}
onClick={() => {
sortUser('role');
}}
>
用户角色
</Table.HeaderCell>
<Table.HeaderCell
style={{ cursor: 'pointer' }}
onClick={() => {
sortUser('status');
}}
>
状态
</Table.HeaderCell>
<Table.HeaderCell>操作</Table.HeaderCell>
</Table.Row>
</Table.Header>
Expand Down

0 comments on commit a2fd920

Please sign in to comment.