like-gold•3y ago
How to add export button to every list page
How to add custom button to create, edit or list page for all
6 Replies
Hi @viveksingh0143. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
In refine, you can add custom buttons to the header of the Create, Edit, or List pages using the
headerButtons property. This property accepts React.ReactNode or a render function, which you can use to keep the existing buttons and add your own.
Here's how you can do it:
For Create Page:
Source (https://refine.dev/docs/api-reference/antd/components/basic-views/create/)
For Edit Page:
Source (https://refine.dev/docs/api-reference/antd/components/basic-views/edit/)
For List Page:
Source (https://refine.dev/docs/api-reference/antd/components/basic-views/list/)
Please note that if the "list" resource is not defined, the ListButton will not render and listButtonProps will be undefined. Similarly, if the "create" resource is not defined or if canCreate is false, the CreateButton will not render and createButtonProps will be undefined.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@940119979334967366> kapa.ai is still learning and improving, please let us know how it did by reacting below
like-goldOP•3y ago
@kapa.ai can we extend the List component as the create button will render when we mention canCreate at meta tag, similarly can we define export functionality to every list page using something similar like canExport
Let me check the knowledge base for you. One moment! :books:
----------------------
Yes, you can extend the List component to include an export button. You can use the
useExport hook provided by refine to add export functionality to your application. This hook can be used to turn any button into an export button.
Here's an example of how you can add an export button to your list page:
In this example, when the user clicks the button, the download process will initialize. You can also manually run the triggerExport function. useExport returns two properties: isLoading: boolean and triggerExport: async () => void. You can use these properties to create your own export button or pass them to the ExportButton component.
However, there's no built-in canExport functionality similar to canCreate in refine. If you want to conditionally render the export button based on some criteria, you would need to implement that logic yourself.
For more detailed information and export settings, you can refer to the useExport docs (https://refine.dev/docs/api-reference/core/hooks/import-export/useExport/).
Source (https://refine.dev/docs/advanced-tutorials/import-export/csv-export/)
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@940119979334967366> kapa.ai is still learning and improving, please let us know how it did by reacting below
uncomfortable-jade•2y ago
Hello @viveksingh0143, was the bot's answer sufficient for you? Let us know if you need more help!