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

How to get the index when using <ng-template>?

Thread ID:

Created:

Updated:

Platform:

Replies:

147403 Sep 9,2019 05:09 PM UTC Sep 10,2019 12:00 PM UTC Angular - EJ 2 1
loading
Tags: ListView
Paul Kocher
Asked On September 9, 2019 05:09 PM UTC

Hi, 

I'm using the ListView template as shown in the docs. I get the data via let-data but I haven't found a way to get hold of the index, first and last properties which are available when using ngFor.

I also haven't found anything in the documentation. How can I get these values (index, first, last)?

Thanks

Paul

Vinoth Kumar Sundara Moorthy [Syncfusion]
Replied On September 10, 2019 12:00 PM UTC

Hi Paul, 
 
Thank you for contacting Syncfusion support. 
 
We have checked your requirement and currently in ListView, Template is not using ngFor to generate its items. Since it is a custom compiler template, we have generated the items based on the given Values. We suggest you use below workaround solution for your requirement by using below response, 
 
Code Example 
<span class="e-list-item-header">index {{this.getIndex(data)}} - {{data.text}}</span> 
 
getIndex(ds) { 
    return this.data.indexOf(ds); 
} 
 
getFirstElement() { 
    return this.data[0]; 
} 
 
getLastElement() { 
    return this.data[this.data.length - 1]; 
} 
 
In ListView the data source is returned in array format so you can get first and last items data by passing first and last index position (0 and data.length-1) to data Source, and you can get the list item index position by passing the item data to indexOf method. 
 
 
Could you please check the above sample and get back to us if you need any further assistance on this? 
 
Regards, 
Vinoth Kumar S 


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