A potential solution could be to make use of expandIconColumnIndex, a prop that can be passed to an expandable antd Table component as well as adding an extra row for the expander. By doing this, you can set the expandIconColumnIndex to the index of the last (empty) row (in your case the index is 4), this way the icon will appear to the right of the Delete action. This will avoid creating space on the left and will move the icon to the right most column. This is the method that requires the least refactor given your code. Below is your updated columns.
const columns = [
{ title: "Name", dataIndex: "name", key: "name" },
{ title: "Age", dataIndex: "age", key: "age" },
{ title: "Address", dataIndex: "address", key: "address" },
{
title: "Action",
dataIndex: "",
key: "x",
render: (r) => <div>
<a>Delete</a>
<a onClick={()=>expandRows(r.key)}> ex</a>
</div>
},
{ title: "", dataIndex: "", key: "expand", width: 1},
];
And here is the updated Table.
<Table
expandIconColumnIndex={4}
columns={columns}
dataSource={data}
expandIcon={({ expanded, onExpand, record }) =>
expanded ? (
<UpOutlined style={{float: 'right'}} onClick={e => onExpand(record, e)} />
) : (
<DownOutlined onClick={e => onExpand(record, e)} />
)
}
expandable={{
expandedRowRender: record => <p style={{ margin: 0 }}>{renderTable()}</p>
}}
/>
In order to remove the left space from the nested table, you will need to overwrite Ant Design's CSS, which includes more padding for the nested table to act as indentation and differentiate it from the rest of the table. I recommend you keep it the way it is but if you really don't want to have that space you can overwrite their style by adding the className parentTable to your first table, and then nestedTable for the nested table (found in renderTable). Then add the following CSS to your style sheet.
.parentTable
table
tbody
.ant-table-expanded-row.ant-table-expanded-row-level-1
> td {
padding: 0px !important;
}
.nestedTable > div > div > div {
width: 100%;
margin-left: 0px !important;
margin-right: 0px !important;
}
Here is the working codesandbox.