How to export all data in paginated or load more Datagrid?

Hi,

I need to download all the data from  Datagrid( paginated and load more ). Now it only downloads the current page rows. Given below code is used for export. Pls help me to download all rows.

   Future<void> _exportDataGridToExcel() async {
    final Workbook workbook = _key.currentState!.exportToExcelWorkbook();

    // print('workbook $workbook');

    //final List<int> bytes = workbook.saveAsCSV(','); //workbook.saveAsStream();

    final List<int> bytes = workbook.saveAsStream();
    workbook.dispose();

    //await helper.saveAndLaunchFile(bytes, 'DataGrid.csv');

    await helper.saveAndLaunchFile(bytes, 'DataGrid.xlsx');
  }


Thanks in advance


3 Replies 1 reply marked as answer

AP Abinesh Palanisamy Syncfusion Team September 28, 2023 12:02 PM UTC

Hi sreesherine krishty,


Currently DataGrid does have support to export only the rows in current page. To export all the rows, you can pass the required rows to rows in the exportToExcelWorkbook extension method. We have prepared the sample for your reference. Please refer to the below code and sample.

Code snippets:

MaterialButton(

  child: const Center(

    child: Text(

      'Export to Excel',

    ),

  ),

  onPressed: () async {

    Workbook workbook = key.currentState!.exportToExcelWorkbook(

        rows: employeeDataSource.entireDataGridRows);

    final List<int> bytes = workbook.saveAsStream();

    workbook.dispose();

    // Save and launch the file

    await helper.saveAndLaunchFile(bytes, 'DataGrid.xlsx');

  },

),

If this post is helpful, please consider Accepting it as the solution so that other members can locate it more quickly.


Regards,

Abinesh P


Attachment: SfDataGridSample_1227144d.zip

Marked as answer

SK sreesherine krishty September 29, 2023 08:35 AM UTC

Hi Abinesh,

Thank you for sharing this code snippet and information regarding exporting data. It works for me.



TP Tamilarasan Paranthaman Syncfusion Team October 2, 2023 07:00 AM UTC

Hi Sreesherine,


We are glad to know that the provided response meets your requirements. Please let us know if you have any further queries on this. We are happy to help.


Regards,

Tamilarasan


Loader.
Up arrow icon