computeHeaderCellWidth method

  1. @protected
double computeHeaderCellWidth(
  1. GridColumn column,
  2. TextStyle style
)

Calculates the width of the header cell based on the GridColumn.columnName. You can override this method to perform the custom calculation for height.

If you want to calculate the width based on different TextStyle, you can override this method and call the super method with the required TextStyle. Set the custom ColumnSizer to SfDataGrid.columnSizer property.

class CustomColumnSizer extends ColumnSizer {
@override
 double computeHeaderCellWidth(GridColumn column,
     TextStyle textStyle) {
  TextStyle style = textStyle;
  if (column.columnName == 'Name')
   style = TextStyle(fontSize: 20, fontStyle: FontStyle.italic);
 return super.computeHeaderCellWidth(column, style);
}
}

The auto size is calculated based on default TextStyle of the datagrid.

Implementation

@protected
double computeHeaderCellWidth(GridColumn column, TextStyle style) {
  return _calculateTextSize(
    column: column,
    textStyle: style,
    width: double.infinity,
    value: column.columnName,
    rowIndex: grid_helper.getHeaderIndex(_dataGridStateDetails!()),
  ).width.ceilToDouble();
}