KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines

Not able to export all data from datagrid when using server side data source #2541

Open DVBI opened this topic on on Jan 21, 2022 - 6 comments

DVBI commented on Jan 21, 2022

Please share the snippet to export all the data from datagrid when using server side processing

Sebastian Morales commented on Jan 21, 2022

Here's a general guide: Use our server side export instead of DataTables' Button client export. In your report setup, uou can check if this is an export request (with $_GET, $_POST, or your request object). If it is, you pipe all data from your source to a datastore called "exportedData". Then in your export view page you use that datastore instead of the one that DataTables uses.

If you are exporting big table data (no chart) to excel, it's advisable to use BigSpreadsheetExportable instead of ExcelExportable as it's faster and uses much less memory.

DVBI commented on Jan 24, 2022

Can you please share example of the above? that will be very helpful.

Thanks

Sebastian Morales commented on Jan 24, 2022

Ok, here's an example code:

//MyReport.view.php
<form method="post">
    <button type="submit" name="exportAllData" formaction="path/to/export.php">Export all data</button>
</form>

//export.php
include "MyReport.php";
$report = new MyReport();
$report
->run()
->exportToExcel(array(
    "dataStores" => array(
        "exportedDataStore" => array()
    )
))
->toBrowser("SalesQuarters.xlsx");

//MyReport.php
function setup()
{
    if (isset($_POST["exportAllData"])) {
        $this->src("myDataSource")
        ->query("select * from MyTable")
        ->pipe($this->dataStore("exportedDataStore"));
    }
    ...
DVBI commented on Jan 28, 2022

Can you please provide some solution which can be integrated from the buttons?

'buttons' => [
                    [
                        'extend' => 'csv',
                        'className' => 'btn btn-default btn-icon',
                        'text' => '<i class="fi fi-rr-file"></i>'
                    ],
                    [
                        'extend' => 'excel',
                        'className' => 'btn btn-default btn-icon',
                        'text' => '<i class="dci dci-file-excel"></i>'
                    ],
                    [
                        'extend' => 'print',
                        'className' => 'btn btn-default btn-icon',
                        'text' => '<i class="fi fi-rr-print"></i>'
                    ],
                ],

I have page similar to this but with server side enabled and had many records. https://www.koolreport.com/examples/reports/datagrid/plugins/

Sebastian Morales commented on Jan 28, 2022

Probably just remap those button to call server side exporting instead of their default client side export, which would never be able to export huge amount of data client-side. You can try to search to "DataTables buttons run javascript function". Then in the js function call server side Export button click. Rgds,

DVBI commented on Jan 28, 2022

Thanks for the help but that won't work for us as we are looking for more generalised solution which can be work with multiple data-tables without writing export each time

Build Your Excellent Data Report

Let KoolReport help you to make great reports. It's free & open-source released under MIT license.

Download KoolReport View demo
help needed

None