-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
[DataGridPremium] Use web worker for Excel export #7770
Conversation
These are the results for the performance tests:
|
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
### Using a web worker | ||
|
||
:::warning | ||
This feature only works with `@mui/styled-engine` v5.11.8 or newer. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because of mui/material-ui#36001
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
::: | ||
|
||
Instead of generating the Excel file locally, you can delegate the task to a web worker. | ||
This method reduces the amount of time that the main thread remains frozen, allowing to interact with the grid while the data is exported in background. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
allowing to interact with the grid
May the interaction interfere with the exported data?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it will be a problem. While the UI is frozen (during serialization) the user can't interact with it, but once interaction is possible is because serialization is finished and the worker is preparing the Excel file.
// Creates a temp worksheet to obtain the column letters | ||
const excelJS = await getExcelJs(); | ||
const workbook: Excel.Workbook = new excelJS.Workbook(); | ||
const worksheet = workbook.addWorksheet('Sheet1'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't get why is it needed, but it should not be a problem
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I need to get the column letters to be able to serialize the value options. The only why I found to get this without duplicating the code was to create a temp worksheet.
packages/grid/x-data-grid-premium/src/hooks/features/export/useGridExcelExport.tsx
Outdated
Show resolved
Hide resolved
packages/grid/x-data-grid-premium/src/models/dataGridPremiumProps.ts
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work! 🚀
) { | ||
// eslint-disable-next-line no-restricted-globals | ||
addEventListener('message', async (event: MessageEvent<ExcelExportInitEvent>) => { | ||
const { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we refactor buildExcel
to use the serialized data instead of apiRef
and reuse buildExcel
in setupExcelExportWebWorker
?
function setupExcelExportWebWorker() {
addEventListener('message', async (event: MessageEvent<ExcelExportInitEvent>) => {
const workbook = await buildExcel(event.data);
postMessage(await workbook.xlsx.writeBuffer());
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be done in a follow-up, I'll open an issue. We need to rework the interfaces for buildExcel
to accept the same params that are passed when the worker is used..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good to me 👍
Preview: https://deploy-preview-7770--material-ui-x.netlify.app/x/react-data-grid/export/#using-a-web-worker
Closes #6772