Skip to content

SFDataGrid Stacked Headers PDF Export Problem #1157

@bahadirarslan

Description

@bahadirarslan

I am using SFDataGrid in one of my projects and facing an issue with Stacked Headers.

In my project, I am using both Excel and pdf exports. Excel export is working tremendously but PDF export has a problem with stacked headers.

This is the result of the Excel export and this is correct.
Screenshot 2023-04-05 at 02 32 03

But this is the result of PDF export, as you can see stacked headers were omitted.
Screenshot 2023-04-05 at 02 31 01

here is the PDF export code

PdfGrid pdfGrid = key.currentState!.exportToPdfGrid(
                              converter: converter,
                              rows: page,
                              excludeColumns: excludeColumns,
                              fitAllColumnsInOnePage: true,
                              cellExport: (details) async {
                                details.pdfCell.style.font = PdfTrueTypeFont(fontBytes, 6);
                              });

Converter code

class CustomDataGridToPdfConverter extends DataGridToPdfConverter {
  int page = 0;

  @override
  PdfGrid exportToPdfGrid(SfDataGrid dataGrid, List<DataGridRow>? rows) {
    (dataGrid.source as LogbookViewModel).silentHandlePageChange(page == 0 ? 0 : page - 1, page);
    return super.exportToPdfGrid(dataGrid, rows);
  }

  @override
  Object? getCellValue(GridColumn column, DataGridRow row) {
    var value = super.getCellValue(column, row);

    if (value.toString() == "0" || value.toString() == "00:00") {
      return "";
    }
    return value;
  }

  @override
  void exportColumnHeader(SfDataGrid dataGrid, GridColumn column, String columnName, PdfGrid pdfGrid) {
    var label = "";
    if (column.label is Text) {
      label = (column.label as Text).data!;
    } else if (column.label is Center) {
      label = ((column.label as Center).child as Text).data!;
    } else {
      label = (((column.label as Padding).child as Center).child as Text).data!;
    }
    super.exportColumnHeader(dataGrid, column, label, pdfGrid);
  }
}

I couldn't find what is wrong with PDF export.

Metadata

Metadata

Assignees

No one assigned

    Labels

    data gridData grid component

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions