How to add a listener to the DataSources created (for data changes - edit/add etc)

Hi, 

I am creating a data source within a viewModel in my app and am having a problem getting the notifyListeneners to trigger as I was intending.
As per the small snippet below; I am creating the sfDatagrid data-source within my view model, and all the data then exists within the sfDataGrid Datasource.

Prior to using sfDatagrid usage, I would perform all data operations in the view model and then call notifyListeners (which updates my UX fine).
Currently when data is loaded (infinite scroll load etc), the datagrid in my UX is refreshing fine - as I am calling notifyDataSourceListeners().

This call, or the additional notifyListeners() however does not trigger a change notification in my parent model.  
An example could be a record count variable shown on screen for example.

I have noticed that you have an ability to addListener - and I wondered of this was intended to be used here...?
I was thinking that I could potentially listen for data changes from the view model and then call "notifyListeners" to update my UX as required..?

 class SupplierViewModel extends BaseViewModel {
  final APIAuthService? _ckAPIService = locator<APIAuthService>();
  final MenuService? _menuService = locator<MenuService>();

  // Datasources; sfDatagrid data source
  SupplierDataSource supplierDataSource = SupplierDataSource();


Great product - keep up the great work...!
Many thanks in advance.

Kind regards
Ian.

1 Reply 1 reply marked as answer

RS Renugadevi Sadagoban Syncfusion Team April 21, 2021 05:37 PM UTC

Hi Ian,  
Thanks for contacting Syncfusion support. 
Please find the following response,  
I have noticed that you have an ability to addListener - and I wondered of this was intended to be used here...?  
  
Yes. You can use addListener method to listen whenever the notifyListener is called. 
I was thinking that I could potentially listen for data changes from the view model and then call "notifyListeners" to update my UX as required..?  
  
Yes. You can call the notifyListers after the data changes. It will update the UI as per the changes.  
 
Please let us know if you require any further assistance on this. 
 
  
Regards, 
Renuga devi S 
 


Marked as answer
Loader.
Up arrow icon