Can we disable the left border (SfDataGrid)?

I see in the patch notes a breaking change was made to show the top/left borders by default:

https://help.syncfusion.com/flutter/release-notes/v20.3.0.47?type=all#datagrid

I want to turn off the left border. I see that if I set GridLinesVisibility.none it turns off the left border, but of course it also turns off all the borders separating my rows. I would have thought that GridLinesVisibility.horizontal would hide the left border, but that's not the case. I can wrap each of my cell widgets with a Container and set a bottom border on them, but if it's possible to handle this with some setting in SfDataGrid I would prefer to do that.

Is there any way to turn off the left border without using GridLinesVisibility.none? ​It would be nice if the top/left borders could be opted out of.


1 Reply

TP Tamilarasan Paranthaman Syncfusion Team June 2, 2023 09:42 AM UTC

Hi Evan Kerik,

As of now, the DataGrid component does not have a built-in option to remove the left and top outer borders. However, you can achieve this requirement using a workaround. One approach is to use the ClipRect widget along with a custom clipper (CustomClipper<Rect>) to remove the left and top outer borders. By applying the ClipRect with the appropriate clipper, you can control the visibility of the borders as desired. To do this, you will need to write a CustomClip class by extending the CustomClipper<Rect> class and setting Rect.fromLTWH with the grid line stroke width value for the left and top in the getClip method. Afterwards, you can wrap the DataGrid as a child of ClipRect. To assist you further, we have prepared a simple sample that demonstrates how to implement this workaround. Please refer to the following code snippet and sample for more information.


  @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,

            columns: getColumns,

          ),

        ));

  }

In CustomLeftClipper class:

class CustomLeftClipper extends CustomClipper<Rect> {

  @override

  Rect getClip(Size size) {

    return Rect.fromLTWH(2, 2, size.width - 2, size.height - 2);

  }

 

  @override

  bool shouldReclip(CustomClipper<Rect> oldClipper) => false;

}


Regards,

Tamilarasan


Attachment: sample_1e6ef821.zip

Loader.
Up arrow icon