Can't removeItem from ListView when using custom fields

Hi!

I need to remove items from the ListView but it doesn't work as expected.

My fields object looks like this;

fields: Object = {
text: 'allergy',
id: 'allergyId'
};

adding works great using this code:

addItem() {
this.allergyList.addItem([{ allergy: 'Tst', allergyId: '11' }]);
}

but when I try to remove an item, the component seems to have problems with the custom fields.

deleteItem() {
this.allergyList.removeItem({ id: '11' });
}

I suppose I need to remove it by the actual field (allerdyId). Intellisense in VS Code gives me errors though.

Also I read I can pass "Fields" to the removeItem method. How would I do that?

I tried removeItem({fields: {id: '.....'}}) but this doesn't work


3 Replies

DL Deepa Loganathan Syncfusion Team September 25, 2018 11:37 AM UTC

Hi Paul Kocher,    
  
Thanks for contacting Syncfusion Support.   
  
Query: I need to remove items from the ListView but it doesn't work as expected   
Intellisense in VS Code gives me errors though.   
  
We have analyzed the shared code snippet and the dataSource id is not properly referred in removeItem method. The removeItem removes the items from listview based on field item mapping with datasource. Please refer to the below code snippet to remove the Item from dataSource.   
  
Regarding Intellisense error:   
Yes, this is a known issue at our end and the fix for this issue will be available in out upcoming Volume 3 SP1 release. Please make use of the below highlighted work-around to get rid of this issue.   
  
deleteItem(args) {    
   listObj.removeItem(<{[key:string]: string} >{allergy: 'Dust Allergy', allergyid: '5e26'})    
}   
  
  
Query: I suppose I need to remove it by the actual field (allerdyId). Also, I read I can pass "Fields" to the removeItem method. How would I do that?    
   
  
Yes, removeItem method removes items based on the name of actual field that is set in fields property as given below. So that you can remove items based on “alleryId”.   
  
this.fields = { text: "allergy", id: "allergyid" };   
  
Also, to remove multiple Items from Listview, you can use removeMultipleItems API available in Listiview.   
 
We request you to go through the below help documents to get a solid understanding of Listview.  
 
Please let us know if you have any further queries. 
  
Regards,    
Deepa L.   




PK Paul Kocher September 26, 2018 08:08 AM UTC

Hi Deepa,

thanks for your answer!

Using the workaround lets me remove the items now. Thanks!

Kind regards

Paul


PN Preethi Nesakkan Gnanadurai Syncfusion Team September 27, 2018 11:30 AM UTC

Hi Paul, 
  
Most welcome. 
  
Please let us know if you need any further assistance. 
  
Regards, 
Preethi 


Loader.
Up arrow icon