Enterprise Edition
Version: 4.xx.xx
Swizzle Ready
Export
<ExportButton>
is an Chakra UI <Button>
with a default export icon and a default text with "Export". It only has presentational value.
localhost:3000
import { useExport } from "@refinedev/core";
import { List, ExportButton } from "@refinedev/chakra-ui";
import {
TableContainer,
Table,
Thead,
Tr,
Th,
Tbody,
Td,
Box,
Text,
} from "@chakra-ui/react";
import { useTable } from "@refinedev/react-table";
import { ColumnDef, flexRender } from "@tanstack/react-table";
const PostList: React.FC = () => {
const columns = React.useMemo<ColumnDef<IPost>[]>(
() => [
{
id: "id",
header: "ID",
accessorKey: "id",
},
{
id: "title",
header: "Title",
accessorKey: "title",
},
],
[],
);
const { getHeaderGroups, getRowModel } = useTable({
columns,
});
const { triggerExport, isLoading: exportLoading } = useExport<IPost>({
mapData: (item) => {
return {
id: item.id,
post_title: item.title,
};
},
pageSize: 10,
maxItemCount: 50,
});
return (
<List
headerButtons={
<ExportButton loading={exportLoading} onClick={triggerExport} />
}
>
<Box position="relative">
<TableContainer whiteSpace="pre-line">
<Table variant="simple">
<Thead>
{getHeaderGroups().map((headerGroup) => (
<Tr key={headerGroup.id}>
{headerGroup.headers.map((header) => (
<Th key={header.id}>
{!header.isPlaceholder &&
flexRender(
header.column.columnDef.header,
header.getContext(),
)}
</Th>
))}
</Tr>
))}
</Thead>
<Tbody>
{getRowModel().rows.map((row) => (
<Tr key={row.id}>
{row.getVisibleCells().map((cell) => (
<Td key={cell.id}>
{flexRender(
cell.column.columnDef.cell,
cell.getContext(),
)}
</Td>
))}
</Tr>
))}
</Tbody>
</Table>
</TableContainer>
</Box>
</List>
);
};
interface IPost {
id: number;
title: string;
}
Good to know:
You can swizzle this component to customize it with the Refine CLI
Properties
hideText
It is used to show and hide the text of the button. When true
, only the button icon is shown.
localhost:3000
import { ExportButton } from "@refinedev/chakra-ui";
import { useExport } from "@refinedev/core";
const MyExportComponent = () => {
const { triggerExport, isLoading } = useExport({
mapData: (item) => {
return {
id: item.id,
title: item.title,
};
},
});
return (
<ExportButton
colorScheme="blue"
hideText={true}
loading={isLoading}
onClick={triggerExport}
/>
);
};
Was this helpful?
loading
It is used to show a loading state on the button when the export process is in progress.
localhost:3000
import { ExportButton } from "@refinedev/chakra-ui";
import { useExport } from "@refinedev/core";
const MyExportComponent = () => {
const { triggerExport, isLoading } = useExport({
mapData: (item) => {
return {
id: item.id,
title: item.title,
};
},
});
return (
<ExportButton
colorScheme="blue"
loading={isLoading}
onClick={triggerExport}
/>
);
};
Was this helpful?
API Reference
Properties
Property | Type | Description | Default |
---|---|---|---|
hideText |
| Whether should hide the text and show only the icon or not. |
|
onClick |
| Sets the handler to handle click event | |
svgIconProps |
| ||
loading |
| Set the loading status of button |
|
External Props:
It also accepts all props of Chakra UI Button.
Was this helpful?