Dashboard customization
Last updated
Last updated
By default, AdminJS comes with a simple dashboard which you may want to customize in most cases.
The customization of the dashboard consists of two required and one optional steps:
Creating a React component for your dashboard
Configuring the dashboard to use your component
(Optional) Creating a handler
for your dashboard to access server data
This step requires you to create a React component which is pretty much straightforward. Please refer to the source code of default dashboard to get started.
useTranslation
hook can be imported from adminjs
library:
The rest of the code can be copied as is and worked on.
Now you will have to tell AdminJS to use your dashboard. This can be achieved by configuring the dashboard
option when instantiating AdminJS
. Please refer to "Writing your own Components" tutorial to find out how you can bundle your dashboard component.
Assuming that this is your ComponentLoader
:
This would be how you override the dashboard:
Restart your server and you should see your new, customized dashboard.
In some cases you might want to access backend data in your dashboard, for example when you would like to display charts or statistics in general. To do this, you have to create a handler
for you dashboard.
The handler your create has to be assigned to dashboard
option in your AdminJS
instance:
You now have the logic for returning the data to the frontend, the last part is accessing it in your dashboard component. To do this, you can use AdminJS's ApiClient
in your React component:
Save your component, restart your server and you're good to go.