|
final
DataGridController dataGridController = DataGridController();
@override
Widget
build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const
Text('Flutter SfDataGrid'),
),
body: Column(
children: [
ElevatedButton(
onPressed:
() {
int
index = _employeeDataSource.dataGridRow.length;
_employeeDataSource.dataGridRow.insert(
index,
const DataGridRow(cells: [
DataGridCell(value: 20000, columnName: 'id'),
DataGridCell(value: 'Tom Bass', columnName: 'name'),
DataGridCell(value: 'Developer', columnName: 'designation'),
DataGridCell(value: 20000, columnName: 'salary')
]));
_employeeDataSource.updateDataGridSource();
WidgetsBinding.instance!.addPostFrameCallback((details) {
dataGridController.scrollToRow(
_employeeDataSource.dataGridRow.length.toDouble());
});
},
child:
const Text('Add a new row')),
Expanded(
child:
SfDataGrid(
source:
_employeeDataSource,
columns:
getColumns,
controller:
dataGridController,
),
),
],
),
);
}
|