Go to current row in a paginated sfDataGrid after rebuild

Selecting a row in a specific page of the grid, we open a new form . Returning to Grid, it will be rebuilt. How we can display the selected row in the specific page, automatically ?


1 Reply

TP Tamilarasan Paranthaman Syncfusion Team February 4, 2022 12:29 PM UTC

 Hi Stefan Tsalapatis, 
You can achieve the requirement by maintaining the selected DataGrid row with the page index in the local collection. In the onPageNavigationStart callback, add the selected rows in the DataGrid controller to a local collection. In the onPageNavigationEnd callback, map selected rows in the collection to DataGrid controller selected rows property based on the page index. We have prepared a sample for that, please check the following sample and code snippet  
Code Snippet: 
Map<String, List<DataGridRow>> selectedRowsCollection = {}; 
List<DataGridRow> selectedRows = []; 
 
SfDataPager( 
                  pageCount: ((_employees.length / _rowsPerPage).ceil()).toDouble(), 
                  direction: Axis.horizontal, 
                  delegate: _employeeDataSource, 
                  controller: _dataPagerController, 
                  onPageNavigationStart: (int pageIndex) { 
                    selectedRows = _dataGridController.selectedRows; 
                    selectedRowsCollection[ 
                            _dataPagerController.selectedPageIndex.toString()] = 
                        selectedRows.toList(); 
                  }, 
                  onPageNavigationEnd: (int pageIndex) { 
                    if (selectedRowsCollection.containsKey('$pageIndex') && 
                        selectedRowsCollection['$pageIndex'] != null && 
                        selectedRowsCollection['$pageIndex']!.isNotEmpty) { 
                      _dataGridController.selectedRows = 
                          selectedRowsCollection['$pageIndex']!; 
                    } 
              }), 
 

Sample Link:  
 
We hope this helps. If we misunderstood anything, please modify the above sample based on your requirement. It will be helpful for us to check on it and provide you with the solution at the earliest. 
  
Regards, 
Tamilarasan P 
  
  
  
  


Loader.
Up arrow icon