Titanium JIRA Archive
Appcelerator Community (AC)

[AC-3482] Hi ,Delete on ListView

GitHub Issuen/a
TypeBug
Priorityn/a
StatusResolved
ResolutionCannot Reproduce
Resolution Date2016-04-18T06:08:29.000+0000
Affected Version/sn/a
Fix Version/sn/a
Componentsn/a
Labelsios
ReporterSachin
AssigneeShak Hossain
Created2016-04-10T19:48:46.000+0000
Updated2016-04-18T06:08:29.000+0000

Description

Hi I am unable to delete selected Item From List View, Please find below sample code. My Index.XML
<Alloy>
	<Window class="container">
		<ListView id="pymtElementsList" defaultItemTemplate="elementTemplate"  height="200" editing="true" onDelete="deletePymtRecord"   allowsSelection="true"
				top="10%" borderColor="grey" borderRadius="3" borderWidth="0.5"
				> 
			<HeaderView>
				<View class="row" layout="horizontal"  height="30" width="100%" backgroundColor="Grey" borderColor="grey" borderWidth="0.5" borderRadius="6" >							
					<Label class="lblAgrhdr" id="editLblID" text="Delete" left="1.5%" width="9%" height="Titanium.UI.SIZE" color="#239142" ></Label>																						 								
				</View>				
			</HeaderView>			
		<Templates> 			
        	<ItemTemplate name="elementTemplate" >          	
        		<View class="listMainView" layout="horizontal">						 		
		 			<Label class="lblPymtType" bindId="PaymentType"   left="12%" width="20%" ></Label>															 
				</View>        	        	                                                   
       	 	</ItemTemplate>
		</Templates>
		
		<ListSection  id="pymtHistListView" dataFunction="laodListView" >
						
		</ListSection>			
	</ListView>
	</Window>
</Alloy>
and Index.js is as follow.
function doClick(e) {
    alert($.label.text);
}


function laodListView()
{
		var listItemsDataArray = [];
		var sections= [];
	var listRow = {};			
		listRow["ItemId"] = {
					text :"1"  
		};			
		listRow["PaymentType"] = {
					text :"ACH"  
		};		
		listRow["properties"] = {
				canEdit : "true" ,
				//allowsSelection:"true",										
		};																					
		listItemsDataArray.push(listRow);
		//$.pymtHistListView.setItems(listItemsDataArray);
		listRow = {};
		listRow["ItemId"] = {
					text :"2"  
		};			
		listRow["PaymentType"] = {
					text :"ACH2"  
		};	
		listRow["properties"] = {
			canEdit : "true" ,
			//allowsSelection:"true",										
		};																						
		listItemsDataArray.push(listRow);
		//$.pymtHistListView.setItems(listItemsDataArray);
		listRow = {};
		listRow["ItemId"] = {
					text :"3"  
		};			
		listRow["PaymentType"] = {
					text :"ACH3"  
		};						
		listRow["properties"] = {
			canEdit : "true" ,
			//allowsSelection:"true",										
		};																							
		listItemsDataArray.push(listRow);
		//$.pymtHistListView.setItems(listItemsDataArray);
		listRow = {};
		listRow["ItemId"] = {
					text :"4"  
		};			
		listRow["PaymentType"] = {
					text :"ACH4"  
		};	
		listRow["properties"] = {
			canEdit : "true" ,
			//allowsSelection:"true",										
		};																						
		listItemsDataArray.push(listRow);
		//$.pymtHistListView.setItems(listItemsDataArray);
			
		Ti.API.info("List View listItemsDataArray= "+JSON.stringify(listItemsDataArray));
		$.pymtHistListView.setItems(listItemsDataArray);
		//$.pymtElementsList.setSections($.pymtHistListView);
}

laodListView();

function deletePymtRecord(e)
{
Ti.API.info("&&&&&&& PymtHistWidget INSIDE Function deleteRecord  "+JSON.stringify(e) );		
	Ti.API.info("$.$.pymtElementsList = "+JSON.stringify($.pymtElementsList));
	Ti.API.info("$.$.pymtHistListView = "+JSON.stringify($.pymtHistListView));
	Ti.API.info("Currently selected Item Section Index = "+e.sectionIndex);
	Ti.API.info("Currently selected Item Item Index = "+e.itemIndex);
	
	alert(" deletePymtRecord event Called ");
	
		
	// Get the clicked item from that section
	var item = e.section.getItemAt(e.itemIndex  ); 
	
	Ti.API.info("Selected Delete Item = "+JSON.stringify(item));
	
	$.pymtElementsList.sections[0].deleteItemsAt(e.itemIndex, item, { animated:true });
	
	//$.pymtHistListView.deleteItemsAt(e.itemIndex, item, { animated:true });
	
	
	
	Ti.API.info("&&&&&&& Leaving function  "+JSON.stringify(e) );
	
	
}

$.index.open();
Please suggest How I can Delete Item At selected Index

Comments

  1. Nazmus Salahin 2016-04-11

    Hello, You can use "deleteItemsAt" to delete a list item row. I am attaching a simple example here. *index.xml*
       <Alloy>
       	<Window class="container">
       		<ListView id="list">
       			<ListSection>
       				<ListItem title="List item 1" color='black'></ListItem>
       				<ListItem title="List item 2" color='black'></ListItem>
       				<ListItem title="List item 3" color='black'></ListItem>
       			</ListSection>
       		</ListView>
       	</Window>
       </Alloy>
       
    *index.js*
       function setListView() {
       	$.list.addEventListener('itemclick', function(e) {
       		e.section.deleteItemsAt(e.itemIndex, 1);
       	});
       
       }
       
       setListView();
       
       $.index.open();
       
       
    Thanks

JSON Source