ColumnSizer class Null safety

Handles the sizing for all the columns in the SfDataGrid.

You can override any available methods in this class to calculate the column width based on your requirement and set the instance to the SfDataGrid.columnSizer.

class CustomGridColumnSizer extends ColumnSizer {
  @override
  double computeHeaderCellWidth(GridColumn column, TextStyle style) {
    return super.computeHeaderCellWidth(column, style);
  }

  @override
  double computeCellWidth(GridColumn column, DataGridRow row, Object? cellValue,
      TextStyle textStyle) {
    return super.computeCellWidth(column, row, cellValue, textStyle);
  }

  @override
  double computeHeaderCellHeight(GridColumn column, TextStyle textStyle) {
    return super.computeHeaderCellHeight(column, textStyle);
  }

  @override
  double computeCellHeight(GridColumn column, DataGridRow row,
      Object? cellValue, TextStyle textStyle) {
    return super.computeCellHeight(column, row, cellValue, textStyle);
  }
}

final CustomGridColumnSizer _customGridColumnSizer = CustomGridColumnSizer();

@override
Widget build(BuildContext context) {
  return SfDataGrid(
    source: _employeeDataSource,
    columnSizer: _customGridColumnSizer,
    columnWidthMode: ColumnWidthMode.auto,
    columns: <GridColumn>[
      GridColumn(columnName: 'id', label: Text('ID')),
      GridColumn(columnName: 'name', label: Text('Name')),
      GridColumn(columnName: 'designation', label: Text('Designation')),
      GridColumn(columnName: 'salary', label: Text('Salary')),
  );
}

Constructors

ColumnSizer()
Creates the ColumnSizer for SfDataGrid widget.

Properties

hashCode int
The hash code for this object. [...]
read-only, inherited
runtimeType Type
A representation of the runtime type of the object.
read-only, inherited

Methods

computeCellHeight(GridColumn column, DataGridRow row, Object? cellValue, TextStyle textStyle) double
Calculates the height of the cell based on the DataGridCell.value. You can override this method to perform the custom calculation for hight. [...]
computeCellWidth(GridColumn column, DataGridRow row, Object? cellValue, TextStyle textStyle) double
Calculates the width of the cell based on the DataGridCell.value. You can override this method to perform the custom calculation for width. [...]
computeHeaderCellHeight(GridColumn column, TextStyle textStyle) double
Calculates the height of the header cell based on the GridColumn.columnName. [...]
computeHeaderCellWidth(GridColumn column, TextStyle style) double
Calculates the width of the header cell based on the GridColumn.columnName. You can override this method to perform the custom calculation for height. [...]
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
inherited
toString() String
A string representation of this object. [...]
inherited

Operators

operator ==(Object other) bool
The equality operator. [...]
inherited