How to perform vertical or horizontal scrolling in Flutter DataTable by mouse dragging in web or desktop platforms?
In the Flutter 2.5 release, the mouse drag scrolling behavior in web and desktop platforms has been changed. The details of the drag scroll behavior are documented in this link.
To enable the drag scrolling by mouse in Flutter DataGrid, wrap the SfDataGrid inside the ScrollConfiguration widget and set the behavior property. You need to set the ScrollConfiguration’s dragDevices property as PointerDeviceKind.touch and PointerDeviceKind.mouse.
The default value of dragDevices is PointerDeviceKind.touch.
late EmployeeDataGridSource _employeeDataGridSource; List<Employee> _employees = <Employee>[]; @override void initState() { super.initState(); _employees = getEmployeeData(); _employeeDataGridSource = EmployeeDataGridSource(employees: _employees); } @override Widget build(BuildContext context) { return Scaffold( body: ScrollConfiguration( behavior: ScrollConfiguration.of(context).copyWith(dragDevices: { PointerDeviceKind.touch, PointerDeviceKind.mouse, }), child: SfDataGrid(source: _employeeDataGridSource, columns: [ GridColumn( columnName: 'id', label: Container( padding: const EdgeInsets.symmetric(horizontal: 16.0), alignment: Alignment.centerRight, child: const Text( 'ID', overflow: TextOverflow.ellipsis, ))), GridColumn( columnName: 'name', label: Container( padding: const EdgeInsets.symmetric(horizontal: 16.0), alignment: Alignment.centerLeft, child: const Text( 'Name', overflow: TextOverflow.ellipsis, ))), GridColumn( columnName: 'designation', label: Container( padding: const EdgeInsets.symmetric(horizontal: 16.0), alignment: Alignment.centerLeft, child: const Text( 'Designation', overflow: TextOverflow.ellipsis, ))), GridColumn( columnName: 'salary', label: Container( padding: const EdgeInsets.symmetric(horizontal: 16.0), alignment: Alignment.centerRight, child: const Text( 'Salary', overflow: TextOverflow.ellipsis, ))) ]))); }
You can download this example on GitHub.
Conclusion
I hope you enjoyed learning about how to perform vertical or horizontal scrolling in Flutter DataTable (SfDataGrid) by mouse dragging in web or desktop platforms.
You can refer to our Flutter DataGrid feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our Flutter DataGrid example to understand how to create and manipulate data.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!