Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom Action is not working properly #64

Open
niksbanna opened this issue Jan 2, 2024 · 0 comments
Open

Custom Action is not working properly #64

niksbanna opened this issue Jan 2, 2024 · 0 comments

Comments

@niksbanna
Copy link

I have created a custom action for my user model to export all users in an Excel file.

for this I have created this action

 actions: {
                  export: {
                    actionType: 'resource',
                    component: false,
                    isAccessible: () => true,
                    handler: async (request, response, context) => {
                      const users = await userModel.find({})
                      const workbook = new ExcelJS.Workbook();
                      const worksheet = workbook.addWorksheet('Users');
                      worksheet.addRow(['first_name', 'last_name', 'phone', 'last_login', 'name', 'email', 'isActive', 'domain_id', 'createdAt']);
                      users.forEach(user => {
                        worksheet.addRow([user.first_name, user.last_name, user.phone, user.last_login, user.name, user.email, user.isActive, user.domain_id, user.createdAt  ]);
                      });
                      response.setHeader('Content-Type', 'text/csv')
                      response.setHeader('Content-Disposition', 'attachment; filename=users.csv')
                      await workbook.csv.write(response);
                      response.end();
                    },
                    guard: 'This will export all users',
                    icon: 'CopyIcon',
                    label: 'Export Users',
                  },
                }

now when I click on the export button it hits the API in the background with 200 status and shows csv format in API response but I don't start downloading or open API response in a new tab or anything that helps the user to download Excel.

I am using exceljs library for exporting users.
I have tried all different methods but nothing helps
I don't want to create a custom component.
if anyone have idea how can I fix this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant