We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

ListView not updating when I add items to my DataSource

I have a EjsListView that I am trying to dynamically update. I am adding items to the DataSource list in code using the .Add() function of a list like so (where CheckoutItems is a list variable data source for the ListView):


var newItem =  new CheckoutItem { Id = item.Id, Name = item.Name, Quantity = 0 };
this.CheckoutItems.Add(newItem);


The above statements do not yield any visible update when bound to a button press or any other event. I can see the changes in the datasource in the debugger though. Interestingly, when I completely redeclare the data source my changes do appear in my EjsListView, like so:

this.CheckoutItems = new List<CheckoutItem> {
            new CheckoutItem { Id = 20, Name = "name1", Quantity = 0 },
            new CheckoutItem { Id = 21, Name = "name2", Quantity = 0 },
            new CheckoutItem { Id = 22, Name = "name3", Quantity = 0 },
            };

3 Replies

MK Muthukrishnan Kandasamy Syncfusion Team November 18, 2019 12:55 AM

Hi Brian, 
 
Thanks for contacting Syncfusion support. 
 
In our ListView component we have provided the AddItem method for adding new items. So, you can use this method to achieve your requirement. We have prepared sample for your convenience. Please refer to the below link for the sample. 
 
  
 
Please let us know if you any concerns. 
 
Regards, 
Muthukrishnan K


BR Brian replied to Muthukrishnan Kandasamy November 18, 2019 07:21 AM

Hi Brian, 
 
Thanks for contacting Syncfusion support. 
 
In our ListView component we have provided the AddItem method for adding new items. So, you can use this method to achieve your requirement. We have prepared sample for your convenience. Please refer to the below link for the sample. 
 
  
 
Please let us know if you any concerns. 
 
Regards, 
Muthukrishnan K

This is very helpful. Thank you.
My only other concern is how would I do the opposite to remove items from this list?
I see that there is a .RemoveItem function, however I am unsure how to correctly reference the items I am trying to remove.


MK Muthukrishnan Kandasamy Syncfusion Team November 18, 2019 09:16 PM

Hi Brian, 
  
 
You can refer to the following code block to pass the corresponding parameters for removing the list items in RemoveItem method of ListView component. 
 
Refer to the below code block: 
 
<EjsButton OnClick="@Remove"> Remove Item</EjsButton> 
 
 
public void Remove() 
     { 
        CheckoutItem data = new CheckoutItem { 
                Id = 20, 
                Name = "name1", 
                Quantity = 0 
        }; 
        list.RemoveItem(data); 
    } 
 
 
Please let us know if you have any concerns. 
 
 
Regards, 
Muthukrishnan K 


Loader.
Live Chat Icon For mobile
Up arrow icon