Skip to content

SyncfusionExamples/How-to-export-Stacked-Header-to-PDF-and-Excel-documents-in-Flutter-DataGrid-SfDataGrid

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

How to export DataGrid content with a Stacked Header to PDF and Excel documents in Flutter DataGrid (SfDataGrid)?

In this article, you can learn about how to export DataGrid content with a Stacked Header to PDF and Excel documents in the Flutter DataGrid.

Initialize the SfDataGrid widget with all the required properties. To ensure proper export of the StackedHeaderRow to Excel or PDF, it is crucial to define the corresponding text within the StackedHeaderCell.text property. As widgets cannot be exported to Excel or PDF, setting this property is essential to provide the appropriate text during the export process of the SfDataGrid to Excel or PDF.

  Future<void> exportDataGridToPDF() async {
    final sf_pdf.PdfDocument document = key.currentState!.exportToPdfDocument();
    final List<int> bytes = document.saveSync();
    await helper.saveAndLaunchFile(bytes, 'DataGrid.pdf');
    document.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Syncfusion Flutter DataGrid'),
      ),
      body: Column(
        children: [
          Container(
            margin: const EdgeInsets.symmetric(vertical: 10),
            width: 250,
            child: ElevatedButton.icon(
                icon: const Icon(Icons.print),
                onPressed: () => exportDataGridToPDF(),
                label: const Text('Export to PDF')),
          ),
          Expanded(
            child: SfDataGrid(
              key: key,
              source: employeeDataSource,
              stackedHeaderRows: [
                StackedHeaderRow(
                  cells: [
                    StackedHeaderCell(
                      text: 'Employee Details', // Text used when exporting
                      columnNames: ['id', 'name', 'designation', 'salary'],
                      child: const Center(child: Text('Employee Details')),
                    ),
                  ],
                ),
              ],
              columns: getColumns,
            ),
          ),
        ],
      ),
    );
  }

You can download the example from GitHub

About

How to export Stacked Header to PDF and Excel documents in Flutter DataGrid (SfDataGrid)

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •