Category / Section
How to disable the outer border in the Flutter DataGrid (SfDataGrid)?.
2 mins read
In this article, we will show you how to disable the outer border in the Flutter DataGrid.
Initialize the SfDataGrid widget with all the required properties. Use the ClipRect widget along with a custom clipper (CustomClipper) to remove the outer borders. To achieve this, create a custom clipper class by extending the CustomClipper class. In the getClip method, use Rect.fromLTWH to set the grid line stroke width for the left and top sides, and specify the appropriate size for the right and bottom sides based on the grid layout. After defining this custom clipper, wrap the SfDataGrid with the ClipRect widget to control the visibility of the borders as desired.
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Flutter SfDataGrid'),
),
body: ClipRect(
clipper: CustomLeftClipper(),
child: SfDataGrid(
columnWidthMode: ColumnWidthMode.fill,
source: _employeeDataSource,
gridLinesVisibility: GridLinesVisibility.both,
headerGridLinesVisibility: GridLinesVisibility.both,
columns: getColumns,
),
));
}
class CustomLeftClipper extends CustomClipper<Rect> {
@override
Rect getClip(Size size) {
return Rect.fromLTWH(2, 2, size.width - 4, size.height - 58);
}
@override
bool shouldReclip(CustomClipper<Rect> oldClipper) => false;
}
You can download this example on GitHub.