Skip to content

Commit dbf0ee2

Browse files
committed
adjust expandIconColumnIndex logic
1 parent 84f3300 commit dbf0ee2

File tree

4 files changed

+23
-2
lines changed

4 files changed

+23
-2
lines changed

examples/childrenIndent.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,23 @@ interface RecordType {
1010
children?: RecordType[];
1111
}
1212

13+
function CustomExpandIcon(props) {
14+
let text;
15+
if (props.expanded) {
16+
text = '⇧ collapse';
17+
} else {
18+
text = '⇩ expand';
19+
}
20+
return (
21+
<a
22+
className="expand-row-icon"
23+
onClick={e => props.onExpand(props.record, e)}
24+
dangerouslySetInnerHTML={{ __html: text }}
25+
style={{ color: 'blue', cursor: 'pointer' }}
26+
/>
27+
);
28+
}
29+
1330
const columns = [
1431
{
1532
title: 'Name',
@@ -113,6 +130,7 @@ const Demo = () => (
113130
data={data}
114131
indentSize={30}
115132
onExpand={onExpand}
133+
expandIcon={CustomExpandIcon}
116134
/>
117135
);
118136

src/Body/BodyRow.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ function BodyRow<RecordType extends { children?: RecordType[] }>(props: BodyRowP
6666
indentSize,
6767
expandIcon,
6868
expandedRowRender,
69+
expandIconColumnIndex,
6970
} = React.useContext(BodyContext);
7071
const { onColumnResize } = React.useContext(ResizeContext);
7172
const [expandRended, setExpandRended] = React.useState(false);
@@ -137,7 +138,7 @@ function BodyRow<RecordType extends { children?: RecordType[] }>(props: BodyRowP
137138

138139
// ============= Used for nest expandable =============
139140
let appendCellNode: React.ReactNode;
140-
if (colIndex === 0 && nestExpandable) {
141+
if (colIndex === (expandIconColumnIndex || 0) && nestExpandable) {
141142
appendCellNode = (
142143
<>
143144
<span

src/Table.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ export interface TableProps<RecordType extends DefaultRecordType>
109109
* !!! DO NOT USE IN PRODUCTION ENVIRONMENT !!!
110110
*/
111111
// Used for antd table transform column with additional column
112-
transformColumns: (columns: ColumnsType<RecordType>) => ColumnsType<RecordType>;
112+
transformColumns?: (columns: ColumnsType<RecordType>) => ColumnsType<RecordType>;
113113
}
114114

115115
function Table<RecordType extends DefaultRecordType>(props: TableProps<RecordType>) {
@@ -523,6 +523,7 @@ function Table<RecordType extends DefaultRecordType>(props: TableProps<RecordTyp
523523
expandRowByClick,
524524
expandedRowRender,
525525
onTriggerExpand,
526+
expandIconColumnIndex,
526527
indentSize,
527528
}}
528529
>

src/context/BodyContext.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export interface BodyContextProps<RecordType = DefaultRecordType> {
2929
expandedRowRender: ExpandedRowRender<RecordType>;
3030
expandIcon: RenderExpandIcon<RecordType>;
3131
onTriggerExpand: TriggerEventHandler<RecordType>;
32+
expandIconColumnIndex: number;
3233
}
3334

3435
const BodyContext = React.createContext<BodyContextProps>(null);

0 commit comments

Comments
 (0)