Ant design show record on row click
How can I show the information of a record (in the show screen) when the corresponding row is clicked in the list view in ant design?
react-router-dom to programmatically navigate to the show page of the clicked record. The handler is set to push a new entry onto the history stack with the path of the show page of the clicked record.<ShowButton>showshowshowshowshowuseNavigationuseNavigationuseNavigationuseNavigationuseNavigationuseNavigationShowButtonShowButtonrenderTable.ColumnrecordItemIdrecordItemIdonRowonRowTableuseHistoryonClickonClick<Table />useGoimport {
List,
useTable,
ShowButton,
} from "@refinedev/antd";
import { Table } from "antd";
const PostList: React.FC = () => {
const { tableProps } = useTable<IPost>();
return (
<List>
<Table {...tableProps} rowKey="id">
<Table.Column dataIndex="id" title="ID" />
<Table.Column dataIndex="title" title="Title" width="100%" />
<Table.Column<IPost>
title="Actions"
dataIndex="actions"
key="actions"
render={(_, record) => (
<ShowButton size="small" recordItemId={record.id} />
)}
/>
</Table>
</List>
);
};
interface IPost {
id: number;
title: string;
} import { List, useTable } from "@refinedev/antd";
import { Table } from "antd";
import { useHistory } from "react-router-dom";
const PostList: React.FC = () => {
const { tableProps } = useTable<IPost>();
const history = useHistory();
return (
<List>
<Table
{...tableProps}
rowKey="id"
onRow={(record) => ({
onClick: () => {
history.push(`/posts/show/${record.id}`);
},
})}
>
<Table.Column dataIndex="id" title="ID" />
<Table.Column dataIndex="title" title="Title" width="100%" />
</Table>
</List>
);
};
interface IPost {
id: number;
title: string;
} import { List, useTable, useNavigation } from "@refinedev/antd";
import { Table } from "antd";
const PostList: React.FC = () => {
const { tableProps } = useTable<IPost>();
const { show } = useNavigation();
return (
<List>
<Table
{...tableProps}
rowKey="id"
onRow={(record) => ({
onClick: () => {
show("posts", String(record.id));
},
})}
>
<Table.Column dataIndex="id" title="ID" />
<Table.Column dataIndex="title" title="Title" width="100%" />
</Table>
</List>
);
};
interface IPost {
id: number;
title: string;
}