Commit 3ef3fd80 by zhaochengxiang

增加rowExpandable

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