Commit 3ef3fd80 by zhaochengxiang

增加rowExpandable

parent 14a68e30
......@@ -450,41 +450,29 @@ const ModelTable = (props) => {
'model-table-sub': modelId
});
let expandable = undefined;
let expandRow = undefined;
if (!modelId) {
let needExpand = false;
(filterData||[]).forEach(record => {
(data||[]).forEach(record => {
if (record?.alreadyCheckedOut) {
needExpand = true;
}
})
if (needExpand) {
expandable = {
expandedRowRender: record => <ModelTable
modelId={record?.checkedOutId}
modelPid={record?.id}
expandRow = (_pid, row) => {
if (!row?.alreadyCheckedOut) return null;
return (
<div style={{ padding: 10 }}>
<ModelTable
modelId={row?.checkedOutId}
modelPid={row?.id}
onSubSelect={onSubSelectChange}
{...props}
/>,
expandIcon: ({ expanded, onExpand, record }) => {
if (!record?.alreadyCheckedOut) return null;
return expanded ? <UpOutlined style={{ fontSize: 10 }} onClick={e => onExpand(record, e)} /> : <DownOutlined style={{ fontSize: 10 }} onClick={e => onExpand(record, e)} />
},
rowExpandable: record => {
return record?.alreadyCheckedOut;
}
};
}
} else {
expandable = {
expandedRowRender: record => <></>,
expandIcon: ({ expanded, onExpand, record }) => {
return null;
},
rowExpandable: record => {
return false;
/>
</div>
)
}
}
}
......@@ -545,20 +533,10 @@ const ModelTable = (props) => {
style={{ blockSize: modelId?'95px':'calc(100vh - 94px - 37px - 57px - 24px)' }}
columns={columns}
rows={modelId?(subData||[]):(data||[])}
expandRow={(_pid, row) => {
if (!row?.alreadyCheckedOut) return null;
return (
<div style={{ padding: 10 }}>
<ModelTable
modelId={row?.checkedOutId}
modelPid={row?.id}
onSubSelect={onSubSelectChange}
{...props}
/>
</div>
)
rowExpandable={(row) => {
return row?.alreadyCheckedOut;
}}
expandRow={expandRow}
getComparator={getComparator}
/>
<RcMenu id={MENU_ID}>
......
......@@ -39,6 +39,7 @@ interface Props<Row> {
}>
// setRows?: (rows: any) => void
expandRow?: (pid: string, row: Row) => React.ReactElement
rowExpandable?: (row: Row) => Boolean
getComparator?: (sortColumn: string) => (a: Row, b: Row) => number
loadMoreRows?: (length: number) => Promise<Row[]> | undefined
}
......@@ -54,9 +55,10 @@ function RowRenderer<Row, SR>(id: string) {
export function getExpandingCol<Row extends RowData, SR>({ colSpan, expand }: {
export function getExpandingCol<Row extends RowData, SR>({ colSpan, expand, expandable }: {
colSpan: () => number
expand?: (pid: string, row: Row) => React.ReactElement
expandable?: (row: Row) => Boolean
}) {
const col: Column<Row, SR> = {
key: 'expanded',
......@@ -79,6 +81,8 @@ export function getExpandingCol<Row extends RowData, SR>({ colSpan, expand }: {
);
}
if (!expandable || !expandable(row)) return <></>;
// 展开收起
return (
<div style={{ cursor: 'pointer', color: isCellSelected ? '#777' : '#ccc' }}
......@@ -140,6 +144,7 @@ function FC<Row extends RowData, SR, K extends React.Key = React.Key>(props: Dat
const {
gridRef, ctxRef,
expandRow,
rowExpandable,
getComparator,
loadMoreRows,
contextMenu, columns, rows, ...rest } = props
......@@ -197,7 +202,7 @@ function FC<Row extends RowData, SR, K extends React.Key = React.Key>(props: Dat
if (expandRow) {
const cols: readonly Column<Row, SR>[] = [
getExpandingCol<Row, SR>({
colSpan: () => cols.length, expand: expandRow
colSpan: () => cols.length, expand: expandRow, expandable: rowExpandable
}),
getSelectCol(() => { // 全选
const rows = []
......
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