|
1 |
| -# How-to-show-an-empty-message-in-Flutter-DataTable |
2 |
| -This demo shows how to show an empty message in Flutter DataTable? |
| 1 | +# How to show an empty message in Flutter DataTable (SfDataGrid)? |
| 2 | + |
| 3 | +In this article, we will show you how to show an empty message in [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) with the necessary properties. It provides built-in support for displaying a placeholder when the data source is empty by setting up the [SfDataGrid.placeholder](https://pub.dev/documentation/syncfusion_flutter_datagrid/latest/datagrid/SfDataGrid/placeholder.html) property. When this property is set, the DataGrid automatically displays the specified widget in the scroll view area. By default, SfDataGrid does not display anything when the data source is empty. Using this property, you can load a custom widget to display when there are no records. |
| 6 | + |
| 7 | +```dart |
| 8 | + @override |
| 9 | + Widget build(BuildContext context) { |
| 10 | + return Scaffold( |
| 11 | + appBar: AppBar(title: const Text('Syncfusion Flutter DataGrid')), |
| 12 | + body: Column( |
| 13 | + children: [ |
| 14 | + Padding( |
| 15 | + padding: const EdgeInsets.all(10.0), |
| 16 | + child: TextButton( |
| 17 | + onPressed: () { |
| 18 | + employeeDataSource._employeeData = []; |
| 19 | + employeeDataSource.notifyListeners(); |
| 20 | + }, |
| 21 | + child: Text('Clear All'), |
| 22 | + ), |
| 23 | + ), |
| 24 | + Expanded( |
| 25 | + child: SfDataGrid( |
| 26 | + source: employeeDataSource, |
| 27 | + columnWidthMode: ColumnWidthMode.fill, |
| 28 | + placeholder: Center( |
| 29 | + child: Column( |
| 30 | + mainAxisSize: MainAxisSize.min, |
| 31 | + children: [ |
| 32 | + Icon(Icons.thumb_down_alt_outlined, size: 30), |
| 33 | + SizedBox(height: 8), |
| 34 | + Text('No Records Found', style: TextStyle(fontSize: 16)), |
| 35 | + ], |
| 36 | + ), |
| 37 | + ), |
| 38 | + columns: <GridColumn>[ |
| 39 | + GridColumn( |
| 40 | + columnName: 'id', |
| 41 | + label: Container( |
| 42 | + padding: EdgeInsets.all(16.0), |
| 43 | + alignment: Alignment.center, |
| 44 | + child: Text('ID'), |
| 45 | + ), |
| 46 | + ), |
| 47 | + GridColumn( |
| 48 | + columnName: 'name', |
| 49 | + label: Container( |
| 50 | + padding: EdgeInsets.all(8.0), |
| 51 | + alignment: Alignment.center, |
| 52 | + child: Text('Name'), |
| 53 | + ), |
| 54 | + ), |
| 55 | + GridColumn( |
| 56 | + columnName: 'designation', |
| 57 | + label: Container( |
| 58 | + padding: EdgeInsets.all(8.0), |
| 59 | + alignment: Alignment.center, |
| 60 | + child: Text('Designation', overflow: TextOverflow.ellipsis), |
| 61 | + ), |
| 62 | + ), |
| 63 | + GridColumn( |
| 64 | + columnName: 'salary', |
| 65 | + label: Container( |
| 66 | + padding: EdgeInsets.all(8.0), |
| 67 | + alignment: Alignment.center, |
| 68 | + child: Text('Salary'), |
| 69 | + ), |
| 70 | + ), |
| 71 | + ], |
| 72 | + ), |
| 73 | + ), |
| 74 | + ], |
| 75 | + ), |
| 76 | + ); |
| 77 | + } |
| 78 | +``` |
| 79 | + |
| 80 | +You can download this example on [GitHub](https://github.com/SyncfusionExamples/How-to-show-an-empty-message-in-Flutter-DataTable). |
0 commit comments