Paginated Flutter SfDataGrid Exporting All Data

I am using SfDataGrid with pagination and I would like to export all data not only the current page but I couldn't achieve it correctly.

My current code is below.

     final excel.Workbook workbook = excel.Workbook();
                      for (var i = 0; i < viewModel.pagedRows.length; i++) {
                        final page = viewModel.pagedRows[i];
                        final excel.Worksheet worksheet = i == 0 ? workbook.worksheets[0] : workbook.worksheets.addWithName(i.toString());
                        key.currentState!.exportToExcelWorksheet(worksheet, rows: page);

                      }

                      final List<int> bytes = workbook.saveAsStream();
                      workbook.dispose();
                      writeToFile('DataGrid.xlsx', bytes);
                      Share.shareFiles([await getFilePath('DataGrid.xlsx')],
                          subject: 'Exported Excel',
                          mimeTypes: ['application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/vnd.ms-excel']);


With this code, I can correctly export paginated data to related worksheets. But the problem is summary rows because the export system uses the current visible datagrid's page's summary values while exporting and this causes data errors in the exported file.

I think I should use `DataGridToExcelConverter` and intervene exporting process however I didn't find a way to do it.


1 Reply

TP Tamilarasan Paranthaman Syncfusion Team September 26, 2022 01:03 PM UTC

Hi Bahadir,


Based on the provided code snippet, you export the entire data by passing the viewModel.pagedRows into the exportToExcelWorksheet.rows property. Can you please confirm whether you have the entire page data collection in the underlying collection or do you get the data on the respective page? And you want to export it as a pagination DataGrid with the respective page summary value, or do you need to export all the data with the whole summary value? Please provide more clear or exact use case details. It will be helpful for us to check on it and provide you with the solution at the earliest.


Regards,

Tamilarasan


Loader.
Up arrow icon