After sorting the datagrid, the cell value does not change.

Hi. I am using syncfusion products well.
Since it is not an English-speaking country, the sentence may be awkward because it uses a translator.

I am testing https://github.com/syncfusion/flutter-examples/tree/master/lib/samples/datagrid/real_time_update/datagrid_real_time_update.dart.

It works fine. However, if you set allowSorting to true and click the header to sort, notifyDataSourceListeners(rowColumnIndex: n) using rowColumnIndex no longer works. If I use notifyDataSourceListeners() with no arguments, the value changes, but it redraws the entire row, which degrades performance.

What should I do?

7 Replies

RS Renugadevi Sadagoban Syncfusion Team May 25, 2021 02:08 PM UTC

Hi David,  
Thanks for your update.  
By default, DataGrid don’t refresh the sorting for individual cell update i.e notifyDataSourceListeners(rowColumnIndex).  Sorting will be automatically refreshed only if the notifyListeners() or notifyDatasourceListeners() method is called. Sorting is the costly operation when we call the notifyDataSourceListeners(rowColumnIndex). To apply the sorting for real time updates case, you can call the sort() method after cell values are updated. 
 
Please refer to the following code snippet: 
 
  void _changeRows(int count) { 
    if (stocks.length < count) { 
      count = stocks.length; 
    } 
 
    for (int i = 0; i < count; ++i) { 
      final int recNo = random.nextInt(stocks.length - 1); 
 
      // Reinitialize the DataGridRow for particular row and call the notify to 
      // view the realtime changes in DataGrid. 
      void updateDataRow() { 
        dataGridRows[recNo] = DataGridRow(cells: [ 
          DataGridCell(columnName: 'symbol', value: stocks[recNo].symbol), 
          DataGridCell(columnName: 'stock', value: stocks[recNo].stock), 
          DataGridCell(columnName: 'open', value: stocks[recNo].open), 
          DataGridCell( 
              columnName: 'previousClose', value: stocks[recNo].previousClose), 
          DataGridCell(columnName: 'lastTrade', value: stocks[recNo].lastTrade), 
        ]); 
      } 
 
      stocks[recNo].stock = stocksData[(random.nextInt(stocksData.length - 1))]; 
      updateDataRow(); 
      updateDataSource(rowColumnIndex: RowColumnIndex(recNo, 1)); 
      stocks[recNo].open = 50.0 + random.nextInt(40); 
      updateDataRow(); 
      updateDataSource(rowColumnIndex: RowColumnIndex(recNo, 2)); 
      updateDataRow(); 
      stocks[recNo].previousClose = 50.0 + random.nextInt(30); 
      updateDataRow(); 
      updateDataSource(rowColumnIndex: RowColumnIndex(recNo, 3)); 
      stocks[recNo].lastTrade = 50 + random.nextInt(20); 
      updateDataRow(); 
      updateDataSource(rowColumnIndex: RowColumnIndex(recNo, 4)); 
      sort(); 
    } 
  } 
 
Please let us know if need any further assistance.  
 
Regards, 
Renuga devi s 



DA David May 25, 2021 11:23 PM UTC

Thanks for your answer.

What I want is that when I click on the header, the sorting is executed once and the values in individual cells are updated in real time with the sorted state.

I don't want the sorting every time the values of individual cells change.

When I click on the header, I just remove all rows, recreate the rows with sorted values, and call notifyDataSourceListeners() once and it seems to behave as I want.

Is there a callback function that gets called when the header is clicked?


RS Renugadevi Sadagoban Syncfusion Team May 26, 2021 09:52 AM UTC

Hi David,  
  
Thanks for your update.  
  
The DataGridSource.handleSort() method will be called when you sort the column. You can override the handleSort() method in DataGridSource class. If you want to perform custom sorting,  you don’t need to call the super.handleSort method. 
 
Please refer following code snippet, 
@override 
  Future<bool> handleSort() { 
    return super.handleSort(); 
  } 
 
Please let us know if need any further assistance.  
  
 
Regards, 
Renuga devi s 



DA David May 27, 2021 02:12 AM UTC

Hi, Renugadevi

Thanks for your update. 

 I used handleSort() to sort _dataGridRows using custom sorting, but since then the value still doesn't change when notifyDataSourceListeners(rowColumnIndex) is called.

Is there any way to update the value using notifyDataSourceListeners(rowColumnIndex) after sorting?



RS Renugadevi Sadagoban Syncfusion Team May 27, 2021 02:29 PM UTC

Hi David, 
Thanks for your update. 
  
Currently, the SfDataGrid does not have the support to entirely write the custom sorting by overriding the handleSort() method. We will update further details about our plan to achieve your requirement by tomorrow [28th May 2021]. We appreciate your patience until then. 
 
  
Regards, 
Renuga devi s 



RS Renugadevi Sadagoban Syncfusion Team May 28, 2021 02:06 PM UTC

Hi David 
Thanks for your patience.  
  

We have considered your request as feature. This feature will be implemented in our 2021 Volume 2 release which is expected to be rolled out on mid of June 2021. We will let you know when this feature is implemented. You can follow up with the below feedback for further follow up

 

we appreciate your patience until then. For further assistance, you can follow the feature request. 
  
Regards, 
Renuga devi S 



RS Renugadevi Sadagoban Syncfusion Team July 1, 2021 05:15 AM UTC

Hi David, 
We are glad to announce that our Essential Studio 2021 Volume 2 Main Release v19.2.0.44 is rolled out and is available for download under the following link. 
  
 
You can refer the below UG link to know about custom sorting, 
  
We thank you for your support and appreciate your patience in waiting for this release. Please get in touch with us if you would require any further assistance. 
  
Regards, 
Renuga devi. 


Loader.
Up arrow icon