How to Auto-Resize Row Height After Data Edit in Flutter DataTable?
In this article, we will show you how to automatically resize the row height after editing data in a Flutter DataTable.
Initialize the SfDataGrid widget with all the required properties. You can achieve this by calling the DataGridController.refreshRow method with the corresponding row index and setting the recalculateRowHeight
property to true within the DataGridSource.onCellSubmit method.
DataGridController dataGridController = DataGridController();
@override
void initState() {
super.initState();
_employees = getEmployeeData();
_employeeDataSource = EmployeeDataSource(_employees, dataGridController);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Syncfusion Flutter DataGrid')),
body: SfDataGrid(
controller: dataGridController,
source: _employeeDataSource,
columns: getColumns,
allowEditing: true,
navigationMode: GridNavigationMode.cell,
selectionMode: SelectionMode.single,
onQueryRowHeight: (details) {
return details.getIntrinsicRowHeight(details.rowIndex);
},
),
);
}
class EmployeeDataSource extends DataGridSource {
EmployeeDataSource(this.employees, this.dataGridController) {
dataGridRows = employees
.map<DataGridRow>((dataGridRow) => dataGridRow.getDataGridRow())
.toList();
}
DataGridController dataGridController;
…
@override
void onCellSubmit(DataGridRow dataGridRow, RowColumnIndex rowColumnIndex,
GridColumn column) {
…
dataGridController.refreshRow(rowColumnIndex.rowIndex,
recalculateRowHeight: true);
}
}
Conclusion
I hope you enjoyed learning how to auto-resize row height after data edit in Flutter DataTable?
You can refer to our Flutter DataTable 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 Flatter DataTable 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!