Commit e89086ec by zhaochengxiang

模型支持排序

parent caf227d9
...@@ -116,7 +116,7 @@ div[id^='__qiankun_microapp_wrapper_'] { ...@@ -116,7 +116,7 @@ div[id^='__qiankun_microapp_wrapper_'] {
} }
.yy-table-tbody > tr > td { .yy-table-tbody > tr > td {
padding: 12px 8px !important; padding: 8px 8px !important;
} }
.yy-table-tbody > .yy-table-measure-row > td { .yy-table-tbody > .yy-table-measure-row > td {
......
...@@ -38,6 +38,7 @@ const ModelTable = (props) => { ...@@ -38,6 +38,7 @@ const ModelTable = (props) => {
const [ selectedRowKeys, setSelectedRowKeys ] = useState([]); const [ selectedRowKeys, setSelectedRowKeys ] = useState([]);
const [ subSelectedRowKeys, setSubSelectedRowKeys ] = useState([]); const [ subSelectedRowKeys, setSubSelectedRowKeys ] = useState([]);
// const [ mouseEnterKey, setMouseEnterKey ] = useState(null); // const [ mouseEnterKey, setMouseEnterKey ] = useState(null);
const [ sortRule, setSortRule ] = useState(null);
const [ filterData, setFilterData ] = useState([]); const [ filterData, setFilterData ] = useState([]);
const [ subData, setSubData ] = useState([]); const [ subData, setSubData ] = useState([]);
...@@ -81,6 +82,8 @@ const ModelTable = (props) => { ...@@ -81,6 +82,8 @@ const ModelTable = (props) => {
dataIndex: 'name', dataIndex: 'name',
width: isSzseEnv?360:160, width: isSzseEnv?360:160,
ellipsis: true, ellipsis: true,
sorter: true,
sortDirections: ['ascend', 'descend'],
render: (text, record, _) => { render: (text, record, _) => {
return ( return (
<Tooltip title={text||''}> <Tooltip title={text||''}>
...@@ -96,6 +99,8 @@ const ModelTable = (props) => { ...@@ -96,6 +99,8 @@ const ModelTable = (props) => {
dataIndex: 'cnName', dataIndex: 'cnName',
width: isSzseEnv?420:160, width: isSzseEnv?420:160,
ellipsis: true, ellipsis: true,
sorter: true,
sortDirections: ['ascend', 'descend'],
render: (text, _, __) => { render: (text, _, __) => {
return ( return (
<Tooltip title={text||''}> <Tooltip title={text||''}>
...@@ -108,6 +113,8 @@ const ModelTable = (props) => { ...@@ -108,6 +113,8 @@ const ModelTable = (props) => {
title: '模型描述', title: '模型描述',
dataIndex: 'remark', dataIndex: 'remark',
ellipsis: true, ellipsis: true,
sorter: true,
sortDirections: ['ascend', 'descend'],
width: 200, width: 200,
render: (text, _, __) => { render: (text, _, __) => {
return ( return (
...@@ -146,6 +153,8 @@ const ModelTable = (props) => { ...@@ -146,6 +153,8 @@ const ModelTable = (props) => {
dataIndex: 'editor', dataIndex: 'editor',
width: 100, width: 100,
ellipsis: true, ellipsis: true,
sorter: true,
sortDirections: ['ascend', 'descend'],
}, },
// { // {
// title: '标签', // title: '标签',
...@@ -331,13 +340,27 @@ const ModelTable = (props) => { ...@@ -331,13 +340,27 @@ const ModelTable = (props) => {
}) })
useEffect(() => { useEffect(() => {
const _data = paginate(data||[], pageNum, pageSize);
const newData = [...data];
if (sortRule) {
if (sortRule.order === 'ascend') {
newData.sort((item1, item2) => {
return item1[sortRule.field].localeCompare(item2[sortRule.field]);
})
} else if (sortRule.order === 'descend') {
newData.sort((item1, item2) => {
return item2[sortRule.field].localeCompare(item1[sortRule.field]);
})
}
}
const _data = paginate(newData||[], pageNum, pageSize);
autoResizeColumns(_data); autoResizeColumns(_data);
setFilterData(_data); setFilterData(_data);
//eslint-disable-next-line react-hooks/exhaustive-deps //eslint-disable-next-line react-hooks/exhaustive-deps
}, [data, pagination]) }, [data, pagination, sortRule])
const autoResizeColumns = (val) => { const autoResizeColumns = (val) => {
if ((val||[]).length>0) { if ((val||[]).length>0) {
...@@ -359,8 +382,8 @@ const ModelTable = (props) => { ...@@ -359,8 +382,8 @@ const ModelTable = (props) => {
}) })
let newColumns = [...columns]; let newColumns = [...columns];
newColumns[1].width = getTextWidth(name)+24; newColumns[1].width = getTextWidth(name)+20;
newColumns[2].width = getTextWidth(cnName)+24; newColumns[2].width = getTextWidth(cnName)+20;
let minWidth = isSzseEnv?200:120; let minWidth = isSzseEnv?200:120;
...@@ -527,6 +550,12 @@ const ModelTable = (props) => { ...@@ -527,6 +550,12 @@ const ModelTable = (props) => {
setColumns(nextColumns); setColumns(nextColumns);
}; };
const onTableChange = (pagination, filters, sorter, extra) => {
if (sorter) {
setSortRule(sorter);
}
}
const rowSelection = { const rowSelection = {
selectedRowKeys, selectedRowKeys,
onChange: onSelectChange, onChange: onSelectChange,
...@@ -604,6 +633,7 @@ const ModelTable = (props) => { ...@@ -604,6 +633,7 @@ const ModelTable = (props) => {
style: { backgroundColor: (record?.id===anchorId)?'#e7f7ff':'transparent' }, style: { backgroundColor: (record?.id===anchorId)?'#e7f7ff':'transparent' },
} }
}} }}
onChange={onTableChange}
expandable={expandable} expandable={expandable}
sticky={!modelId} sticky={!modelId}
/> />
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment