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

DataTableExporterResponseEvent should contain instance of DataTable #351

Open
MIvanIsten opened this issue Jul 23, 2024 · 1 comment
Open

Comments

@MIvanIsten
Copy link

MIvanIsten commented Jul 23, 2024

If there are multiple tables on same page with export, each adding own DataTableExporterEvents::PRE_RESPONSE event listener, exporting any of the tables, fires all registered DataTableExporterEvents::PRE_RESPONSE events. The export file name is overwriten by each event.
As a result every export file is named by last fired event.

$table1 = $dataTableFactory->create()
    ->setName('dt-1')
    ->add(...)
    ->addEventListener(DataTableExporterEvents::PRE_RESPONSE, function (DataTableExporterResponseEvent $e) {
        $response = $e->getResponse();
        $ext = $response->getFile()->getExtension();
        $response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, 'table-1-export.' . $ext);
    })
    ->handleRequest($request);
$table2 = $dataTableFactory->create()
    ->setName('dt-2')
    ->add(...)
    ->addEventListener(DataTableExporterEvents::PRE_RESPONSE, function (DataTableExporterResponseEvent $e) {
        $response = $e->getResponse();
        $ext = $response->getFile()->getExtension();
        $response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, 'table-2-export.' . $ext);
    })
    ->handleRequest($request);

expected output
export from table1 named as table-1-export.xlsx
export from table2 named as table-2-export.xlsx

current output
export from table1 named as table-2-export.xlsx
export from table2 named as table-2-export.xlsx

DataTableExporterResponseEvent should contain instance of DataTable, so we can decide inside event callback to skip it if it belongs to other table.

Or fix DataTableExporterManager to dispatch only events that belong to exported DataTable.

Copy link

Stale issue message

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Sep 28, 2024
@curry684 curry684 reopened this Oct 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants