|
1 | | -# How-to-change-the-textStyle-of-the-header-cells-in-a-Flutter-DataTable-SfDataGrid |
2 | | -How to change the textStyle of the header cells in a Flutter DataTable (SfDataGrid). |
| 1 | +# How to change the textStyle of the header cells in a Flutter DataTable (SfDataGrid)?. |
| 2 | + |
| 3 | +In this article, we will show you how to change the textStyle of the header cells in a [Flutter DataTable](https://www.syncfusion.com/flutter-widgets/flutter-datagrid). |
| 4 | + |
| 5 | +Initialize the [SfDataGrid](https://pub.dev/documentation/syncfusion_flutter_datagrid/latest/datagrid/SfDataGrid-class.html) widget with all the necessary properties. The [GridColumn.label](https://pub.dev/documentation/syncfusion_flutter_datagrid/latest/datagrid/GridColumn/label.html) is used to display the required widget in a column header. Under the label property of [GridColumn](https://pub.dev/documentation/syncfusion_flutter_datagrid/latest/datagrid/GridColumn-class.html), the corresponding header text widget is loaded. Therefore, you can add the required header text style to the loaded text widget. |
| 6 | + |
| 7 | +```dart |
| 8 | + @override |
| 9 | + Widget build(BuildContext context) { |
| 10 | + return Scaffold( |
| 11 | + appBar: AppBar( |
| 12 | + title: const Text('Syncfusion Flutter DataGrid'), |
| 13 | + ), |
| 14 | + body: SfDataGrid( |
| 15 | + source: employeeDataSource, |
| 16 | + columnWidthMode: ColumnWidthMode.fill, |
| 17 | + columns: <GridColumn>[ |
| 18 | + GridColumn( |
| 19 | + columnName: 'id', |
| 20 | + label: Container( |
| 21 | + padding: const EdgeInsets.all(16.0), |
| 22 | + alignment: Alignment.center, |
| 23 | + child: const Text( |
| 24 | + 'ID', |
| 25 | + style: TextStyle( |
| 26 | + color: Colors.red, fontWeight: FontWeight.bold), |
| 27 | + ))), |
| 28 | + GridColumn( |
| 29 | + columnName: 'name', |
| 30 | + label: Container( |
| 31 | + padding: const EdgeInsets.all(8.0), |
| 32 | + alignment: Alignment.center, |
| 33 | + child: const Text( |
| 34 | + 'Name', |
| 35 | + style: TextStyle( |
| 36 | + color: Colors.green, fontWeight: FontWeight.bold), |
| 37 | + ))), |
| 38 | + GridColumn( |
| 39 | + columnName: 'designation', |
| 40 | + label: Container( |
| 41 | + padding: const EdgeInsets.all(8.0), |
| 42 | + alignment: Alignment.center, |
| 43 | + child: const Text( |
| 44 | + 'Designation', |
| 45 | + style: TextStyle( |
| 46 | + color: Colors.blueAccent, fontWeight: FontWeight.bold), |
| 47 | + overflow: TextOverflow.ellipsis, |
| 48 | + ))), |
| 49 | + GridColumn( |
| 50 | + columnName: 'salary', |
| 51 | + label: Container( |
| 52 | + padding: const EdgeInsets.all(8.0), |
| 53 | + alignment: Alignment.center, |
| 54 | + child: const Text( |
| 55 | + 'Salary', |
| 56 | + style: TextStyle( |
| 57 | + color: Colors.pink, fontWeight: FontWeight.bold), |
| 58 | + ))), |
| 59 | + ], |
| 60 | + ), |
| 61 | + ); |
| 62 | + } |
| 63 | +``` |
| 64 | + |
| 65 | +You can download this example in [GitHub](https://github.com/SyncfusionExamples/How-to-change-the-textStyle-of-the-header-cells-in-a-Flutter-DataTable-SfDataGrid). |
0 commit comments