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. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

ListView not updating when I add items to my DataSource

Thread ID:

Created:

Updated:

Platform:

Replies:

149152 Nov 15,2019 08:53 PM UTC Nov 19,2019 05:16 AM UTC Blazor 3
loading
Tags: ListView
Brian
Asked On November 15, 2019 08:53 PM UTC

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 },
            };

Muthukrishnan Kandasamy [Syncfusion]
Replied On November 18, 2019 08:55 AM UTC

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

Brian
Replied On November 18, 2019 03:21 PM UTC

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.

Muthukrishnan Kandasamy [Syncfusion]
Replied On November 19, 2019 05:16 AM UTC

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 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon