Hello~:)
In my case i want to show last selected hint(red color *) before checkbox.
May i show other GridColumn in front of checkboxColumn?
Or can i change checkboxColumn position?
the following is
my demo photo(problem):
the following is my code:
Hi~ Tamilarasan : )
If I not set showCheckboxColumn to true and manual DIY datagrid column child widget for selection.
But just laborious.
Thanks for your reply.
Hi Jimmy,
As we said in the previous update, we add the CheckBoxColumn as the first column in the DataGrid. Meanwhile, we are checking your requirement to achieve it at the sample level. We will update you with the details tomorrow i.e., April 19, 2022. We appreciate your patience until then.
Regards,
Tamilarasan
Hi Tamilarasan~
Thanks you for support.
You can achieve your requirement at the sample level itself by the following the below steps,
Step 1: Add the Checkbox widget directly in the DataGrid cell instead of setting the showCheckboxColumn to true. You can add the checkbox column where you need it. Please check the following code snippet.
Code Snippet:
|
@override DataGridRowAdapter buildRow(DataGridRow row) { return DataGridRowAdapter( cells: row.getCells().map<Widget>((e) { if (e.columnName == 'checkbox') { isSelected = dataGridController.selectedRows.contains(row) ? true : false; return Container( alignment: Alignment.center, padding: const EdgeInsets.all(8.0), child: Checkbox( value: isSelected, onChanged: (value) { if (value != null) { if (!value) { if (newSelectedRows.isNotEmpty) { newSelectedRows.clear(); } newSelectedRows = List.from(dataGridController.selectedRows); newSelectedRows.remove(row); dataGridController.selectedRows = List.from(newSelectedRows); } if (value) { dataGridController.selectedRow = row; } notifyListeners(); } }, )); } return Container( alignment: Alignment.center, padding: const EdgeInsets.all(8.0), child: Text( e.value.toString(), ), ); }).toList()); } |
Step 2: For the latest selected hint column, you can show the hint based on the row which is recently added in the dataGridController.selectedRows. Please check the following code snippet.
Code Snippet:
|
getValue(DataGridRow row) { if (dataGridController.selectedRows.isNotEmpty) { return dataGridController.selectedRows.last == row ? '*' : ''; } else { return ''; } }
@override DataGridRowAdapter buildRow(DataGridRow row) { return DataGridRowAdapter( cells: row.getCells().map<Widget>((e) { if (e.columnName == 'isShowSelectedHint') { return Container( alignment: Alignment.center, padding: const EdgeInsets.all(8.0), child: Text( getValue(row), style: const TextStyle(color: Colors.red), ), ); } } |
Step 3: Call the notifyListeners from the DataGridSource class in the DataGrid’s onSelectionChanged callback. It will update the recently selected row hint. Please check the following code snippet and sample.
Code Snippet:
|
@override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: const Text('Syncfusion Flutter DataGrid'), ), body: Center( child: SizedBox( width: MediaQuery.of(context).size.width * 0.8, height: MediaQuery.of(context).size.height * 0.8, child: SfDataGrid( controller: _dataGridController, source: employeeDataSource, columnWidthMode: ColumnWidthMode.fitByCellValue, selectionMode: SelectionMode.multiple, onSelectionChanged: (List<DataGridRow> addedRows, List<DataGridRow> removedRows) { employeeDataSource.updateDataGridSource(); }, columns: getColumns)))); } |
Sample Link: https://www.syncfusion.com/downloads/support/directtrac/general/ze/sample1039089352
We hope this helps. Please let us know if need any further assistance.
Regards,
Tamilarasan
Hi ~ Tamilarasan,
This sample very useful.
Thanks for your help : )
Hi Jimmy,
We are glad that the provided response meets your requirement. Please let us know if you need further assistance. As always, we are happy to help you out.
Regards
Tamilarasan