Hi,
buildGridRows();
notifyListeners();
// userGridController.selectedIndex= pos;
userGridController.selectedRow = _usersDataSource.dataGridRows[pos];
// userGridController.scrollToRow(pos.toDouble());
What is the best way to do the steps 2 ,3,4
thank you
Hi Stefan,
As per your requirement, you can achieve that using the DataGridController. After adding the DataGrid row into the underline collection call the notifyListeners from the DataGridSource class, find the added row index from the DataGridSource.effectiveRows property. Then, assign that index to the DataGridController.selectedIndex for selecting the current added row and using the DataGridController.scrollToRow property for scrolling into the added row. We have prepared a sample for that. Please check the following sample and code snippet.
|
@override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: const Text('Syncfusion Flutter DataGrid'), ), body: Column( children: [ Card( margin: const EdgeInsets.all(20), child: ElevatedButton( onPressed: (() { DataGridRow dataGridRow =
DataGridRow(cells: DataGridCell columnName: 'ID', value: random.nextInt(2000)), const
DataGridCell columnName: 'Name', value: 'Jack'), const
DataGridCell columnName: 'Designation', value: 'C.E.O'), const
DataGridCell ]); _employeeDataSource.datagridRows.add(dataGridRow);
_employeeDataSource.updateDataGridSource();
int index = _employeeDataSource.effectiveRows.indexOf(dataGridRow);
dataGridController.selectedIndex = index;
dataGridController .scrollToRow(dataGridController.selectedIndex.toDouble()); }), child: const Text('Add Row')), ), Expanded( child: SfDataGrid( source: _employeeDataSource, controller: dataGridController, columnWidthMode: ColumnWidthMode.fill, selectionMode: SelectionMode.single, columns: getColumns)), ], ), ); } }
In DataGridSource class:
class EmployeeDataSource extends DataGridSource {
…
void updateDataGridSource() { notifyListeners(); } } |
Sample Link: https://www.syncfusion.com/downloads/support/directtrac/general/ze/sample425532589
We hope this helps. Please let us know if you need any further assistance with this.
Regards,
Tamilarasan
Attachment: Demo_f2e78386.zip
Thanks