Right to Left (RTL) in Flutter DataGrid (SfDataGrid)
22 May 20259 minutes to read
SfDataGrid supports right-to-left rendering. The columns will be rendered based on LTR and RTL direction.
RTL rendering ways
Right-to-left rendering can be switched in the following ways:
Wrapping the SfDataGrid with the Directionality widget
To change the rendering direction from right to left, wrap the SfDataGrid widget inside the Directionality widget and set the textDirection property as TextDirection.rtl.
import 'package:syncfusion_flutter_datagrid/datagrid.dart';
@override
Widget build(BuildContext context) {
return Directionality(
textDirection: TextDirection.rtl,
child: SfDataGrid(
source: _employeeDataSource,
columnWidthMode: ColumnWidthMode.fill,
columns: <GridColumn>[
GridColumn(
columnName: 'id',
label: Container(
padding: EdgeInsets.all(16.0),
alignment: Alignment.center,
child: Text(
'ID',
))),
GridColumn(
columnName: 'name',
label: Container(
padding: EdgeInsets.all(8.0),
alignment: Alignment.center,
child: Text('Name'))),
GridColumn(
columnName: 'designation',
label: Container(
padding: EdgeInsets.all(8.0),
alignment: Alignment.center,
child: Text(
'Designation',
overflow: TextOverflow.ellipsis,
))),
GridColumn(
columnName: 'salary',
label: Container(
padding: EdgeInsets.all(8.0),
alignment: Alignment.center,
child: Text('Salary'))),
]));
}Changing the locale to RTL languages
To change the Datagrid rendering direction from right to left, change the locale to any of the RTL languages such as Arabic, Persian, Hebrew, Pashto, and Urdu.
To use flutter_localizations, add the package as a dependency to pubspec.yaml file.
dependencies:
flutter_localizations:
sdk: flutterThen, import the flutter_localizations library, specify localizationsDelegates and supportedLocales for MaterialApp.