diff --git a/Flutter/datagrid/images/swiping/flutter-datagrid-individual-swiping.gif b/Flutter/datagrid/images/swiping/flutter-datagrid-individual-swiping.gif new file mode 100644 index 000000000..9c3695a09 Binary files /dev/null and b/Flutter/datagrid/images/swiping/flutter-datagrid-individual-swiping.gif differ diff --git a/Flutter/datagrid/scrolling.md b/Flutter/datagrid/scrolling.md index 791ca84ed..89b1fed34 100644 --- a/Flutter/datagrid/scrolling.md +++ b/Flutter/datagrid/scrolling.md @@ -752,4 +752,73 @@ The `rowsCacheExtent` property will create the additional rows internally with t {% endhighlight %} {% endtabs %} -![Flutter DataTable shows increase row cache extent](images/scrolling/flutter-datagrid-increase-row-cache-extent.gif) \ No newline at end of file +![Flutter DataTable shows increase row cache extent](images/scrolling/flutter-datagrid-increase-row-cache-extent.gif) + +## Set height and width of DataGrid based on rows and columns available + +If the height or width of the DataGrid is infinity, then DataGrid sets its height or width to 300 by default. Users can set the height or width based on the number of rows or columns available in DataGrid by using the `shrinkWrapRows` or `shrinkWrapColumns` property, respectively. + +>**NOTE** + Shrink wrapping is significantly more expensive than setting the height and width manually. + +{% tabs %} +{% highlight Dart %} + +import 'package:syncfusion_flutter_datagrid/datagrid.dart'; + +late EmployeeDataSource _employeeDataSource; + + @override + Widget build(BuildContext context) { + return LayoutBuilder(builder: (context, constraints) { + return SingleChildScrollView( + child: SfDataGrid( + shrinkWrapColumns: true, + shrinkWrapRows: true, + source: _employeeDataSource, + columns: [ + GridColumn( + columnName: 'id', + label: Container( + padding: EdgeInsets.symmetric(horizontal: 16.0), + alignment: Alignment.centerRight, + child: Text( + 'ID', + overflow: TextOverflow.ellipsis, + ))), + GridColumn( + columnName: 'name', + label: Container( + padding: EdgeInsets.symmetric(horizontal: 16.0), + alignment: Alignment.centerLeft, + child: Text( + 'Name', + overflow: TextOverflow.ellipsis, + ))), + GridColumn( + columnName: 'designation', + label: Container( + padding: EdgeInsets.symmetric(horizontal: 16.0), + alignment: Alignment.centerLeft, + child: Text( + 'Designation', + overflow: TextOverflow.ellipsis, + ))), + GridColumn( + columnName: 'salary', + label: Container( + padding: EdgeInsets.symmetric(horizontal: 16.0), + alignment: Alignment.centerRight, + child: Text( + 'Salary', + overflow: TextOverflow.ellipsis, + ))), + ], + ), + ); + }); + } + +{% endhighlight %} +{% endtabs %} + diff --git a/Flutter/datagrid/swiping.md b/Flutter/datagrid/swiping.md index 73a7db1da..b69ab09c0 100644 --- a/Flutter/datagrid/swiping.md +++ b/Flutter/datagrid/swiping.md @@ -260,4 +260,110 @@ Widget build(BuildContext context) { {% endhighlight %} {% endtabs %} -![flutter datagrid shows customized swiping delete functionality](images/swiping/flutter-datagrid-customized-swiping-delete-funtionality.gif) \ No newline at end of file +![flutter datagrid shows customized swiping delete functionality](images/swiping/flutter-datagrid-customized-swiping-delete-funtionality.gif) + +## Set different swipe offsets for right and left swiping + +You can set the different swipe offsets based on swipe direction by using the `onSwipeStart` callback and passing the required swipe offset to the `setSwipeMaxOffset` method from the `onSwipeStart` callback's argument. + +{% tabs %} +{% highlight Dart %} + +import 'package:syncfusion_flutter_datagrid/datagrid.dart'; + +late EmployeeDataSource employeeDataSource; + +@override + Widget build(BuildContext context) { + return LayoutBuilder(builder: (context, constraints) { + return SfDataGrid( + allowSwiping: true, + source: employeeDataSource, + onSwipeStart: (details) { + if (details.swipeDirection == DataGridRowSwipeDirection.startToEnd) { + details.setSwipeMaxOffset(200); + } else if (details.swipeDirection == DataGridRowSwipeDirection.endToStart) { + details.setSwipeMaxOffset(100); + } + return true; + }, + startSwipeActionsBuilder: + (BuildContext context, DataGridRow row, int rowIndex) { + return GestureDetector( + onTap: () { + employeeDataSource.dataGridRow.insert( + rowIndex, + DataGridRow(cells: [ + DataGridCell(value: 1011, columnName: 'id'), + DataGridCell(value: 'Tom Bass', columnName: 'name'), + DataGridCell( + value: 'Developer', columnName: 'designation'), + DataGridCell(value: 20000, columnName: 'salary') + ])); + employeeDataSource.updateDataGridSource(); + }, + child: Container( + color: Colors.greenAccent, + child: Center( + child: Icon(Icons.add), + ))); + }, + endSwipeActionsBuilder: + (BuildContext context, DataGridRow row, int rowIndex) { + return GestureDetector( + onTap: () { + employeeDataSource.dataGridRow.removeAt(rowIndex); + employeeDataSource.updateDataGridSource(); + }, + child: Container( + color: Colors.redAccent, + child: Center( + child: Icon(Icons.delete), + ))); + }, + columns: [ + GridColumn( + columnName: 'id', + label: Container( + padding: EdgeInsets.symmetric(horizontal: 16.0), + alignment: Alignment.centerRight, + child: Text( + 'ID', + overflow: TextOverflow.ellipsis, + ))), + GridColumn( + columnName: 'name', + label: Container( + padding: EdgeInsets.symmetric(horizontal: 16.0), + alignment: Alignment.centerLeft, + child: Text( + 'Name', + overflow: TextOverflow.ellipsis, + ))), + GridColumn( + columnName: 'designation', + label: Container( + padding: EdgeInsets.symmetric(horizontal: 16.0), + alignment: Alignment.centerLeft, + child: Text( + 'Designation', + overflow: TextOverflow.ellipsis, + ))), + GridColumn( + columnName: 'salary', + label: Container( + padding: EdgeInsets.symmetric(horizontal: 16.0), + alignment: Alignment.centerRight, + child: Text( + 'Salary', + overflow: TextOverflow.ellipsis, + ))), + ], + ); + }); + } + +{% endhighlight %} +{% endtabs %} + +![flutter datagrid shows swiping a row in both directions with different swiping offset](images/swiping/flutter-datagrid-individual-swiping.gif) \ No newline at end of file