Angular 2 Table Serial Number

I have data coming in from an API and I want to display it in a table. In the table, there is a column for serial numbers (#). Currently, I am able to show the serial numbers starting from 1 on every page. However, when I switch pages, the counting starts again from 1 instead of continuing where it left off.

Image page 1

https://i.sstatic.net/fZPzw.png

Image page 2

https://i.sstatic.net/3I6kK.png

Code

<tbody>
            <tr *ngFor="let user of _data | paginate: { itemsPerPage: 10, currentPage: p }; let i=index">
                <th>{{i + 1}}</th>
            

<th>{{user.FirstName}}</th>
                <th>{{user.LastName}}</th>
                <th>{{user.Email}}</th>
                <th>
                    
                    <button *ngIf="user.IsActive==false" class="btn btn-success btn-xs" (click)="changeStatus(user.Id)"> <i class="fa fa-check"></i> Active </button>
                    <button *ngIf="user.IsActive==true" class="btn btn-danger btn-xs" (click)="changeStatus(user.Id)"><i class="fa fa-trash-o"></i> Block</button>}}
                </th>


            </tr>
        </tbody>

Answer №1

The solution.

{{ (settings.pageNumber - 1) * settings.itemsPerPage + i +1 }}

Answer №2

To achieve the desired outcome, you can use a code snippet like this:

<th>{{(currentPage + 1) * itemsPerPage + i + 1}}</th>

This code will serve your purpose effectively.

Keep in mind that *ngFor is only aware of the items on the current page, as provided by _data | paginate.

Answer №3

Here's an example of how you can utilize it:

{{$index +1}}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What are some efficient methods for verifying and overseeing user credentials in a Spring Boot Angular 8 web application?

Currently, I am working on developing a website with Angular 8 for the frontend, Spring Boot, Maven, Hibernate, and MySQL for the backend. Although I have a basic understanding of authentication and user management, I am struggling to implement login funct ...

Determining the sequence of events for @HostListener event within an Angular directive

I am facing an issue with my Angular 9 application wherein a parent component contains a child component (referred to as "overview") which has a button. Upon clicking the button, the child component emits an event that should be handled by the parent compo ...

Exploring the options variables within CLI commander Js action

As a newcomer to developing CLI apps, I've chosen to work with ts-node and commander. However, I'm currently facing a challenge in understanding how to access the options that users pass into my command action. program .version(version) .nam ...

Tips on saving a moved option item from one table to another in HTML:

Having an issue with dragging tables between different lists in Angular. The tables are generated by separate ngFor loops and I am using cdkDrag for the drag and drop functionality. The problem arises when I set an option in a dropdown and then drag the ta ...

The essential guide to creating a top-notch design system with Material UI

Our company is currently focusing on developing our design system as a package that can be easily installed in multiple projects. While the process of building the package is successful, we are facing an issue once it is installed and something is imported ...

Display a loading spinner icon upon the initial load of an Angular5 application on the main page

My goal is to display a spinner icon in the center of the Angular app login page upon loading. Here is the index.html code for the Angular app: <!doctype html> <html> <head lang="en"> <meta charset="utf-8> & ...

How to link Array with Observable in Angular2 Typescript without using .interval()

Is it possible to achieve the same functionality without using the "interval()" method? I would like to link an array to an observable, and update the array as well as have the observable monitor the changes. If this approach is feasible, how can we inco ...

How does the kendo parseNumber function handle the input "NaN"?

Can anyone point me to the code for the Telerik Kendo Angular function parseNumber? I've noticed that it successfully parses "Infinity" but not "NaN", converting it to null. Any insights on why this happens and how it can be resolved? Thanks! ...

Exploring Angular's filtering capabilities and the ngModelChange binding

Currently, I am in the process of working on a project for a hotel. Specifically, I have been focusing on developing a reservation screen where users can input information such as the hotel name, region name, check-in and check-out dates, along with the nu ...

Creating a simulated provider class to simulate a response and manage promises - Implementing Unit Testing using Jasmine and Karma within an Ionic 3 environment

I am relatively new to Unit Testing and have recently started writing tests for my Ionic 3 Application using Karma and Jasmine. I referred to blogs to configure everything correctly and successfully tested the initialization of App component. Additionally, ...

Unresolved promise: Issue encountered with StaticInjectorError within AppModule linking to HttpHeaders:

I am currently working on an ionic v3 project and facing a particular issue. The problem is similar to #47492475, even though I have already imported HttpClientModule in app.module.ts. Despite this import, the error continues to persist. Below are my .ts f ...

If I exclusively utilize TypeScript with Node, is it possible to transpile it to ES6?

I am developing a new Node-based App where browser-compatibility is not a concern as it will only run on a Node-server. The code-base I am working with is in TypeScript. Within my tsconfig.json, I have set the following options for the compiler: { "inc ...

Tips on executing an asynchronous operation before exiting

I have been attempting to execute an asynchronous operation before my process ends. By 'ends', I mean in every instance of termination: ctrl+c Uncaught exception Crashes End of code Anything.. As far as I know, the exit event handles this for ...

Encountering an issue while trying to execute the command "ionic cordova build android --prod --release

Currently, I am facing an issue while trying to build my apk for deployment on the Play Store. The error message is causing a time constraint and I urgently need to resolve it. Any help or suggestions regarding this matter would be greatly appreciated. ...

From HTML element to pug-template with the use of the # symbol

I have a code snippet with 2 angular material radio buttons. Both of them contain the #attribute/element (I'm not sure what it's called) within them. How can I convert them into pug so that the attribute/element with the # works? Below is the sam ...

Integrate AngularJS service with Angular framework

Attempting to utilize the $log service within an angular 2 app, it seems that the following steps are necessary: Set up a module that includes the service you wish to inject. Utilize UpgradeAdapter's upgradeNg1Provider method. Therefore, I proceede ...

Utilizing the class decorator pattern in TypeScript with a recursive original class method: A guide

For clarity, I am utilizing the decorator pattern/approach from and not the experimental decorators feature in TypeScript. The scenario involves extending the next method on the main class Foo. Various features are implemented by different classes like B ...

Transforming an Established React Project into a Progressive Web Application

Currently, I have an existing react tsx project that has been set up. My goal is to transform it into a PWA by adding service workers. However, after adding the service workers in the src folder, I encountered an error when attempting to deploy on firebase ...

"Exploring the dynamic duo of Angular2 and ng2Material

I am currently facing an issue with the styling in my code while using ng2Material with Angular2. First: A demonstration of Material style functioning properly can be seen in this plunker. When you click on the button, you will notice an animation effect. ...

Encountering issues with Typescript when providing parameters for res.status().json()

I've recently started using Typescript and I'm still in the learning process by converting some existing JS code to TS. In my code: res.status(200).json({ user: data.user }) I encountered a red squiggly underline under user:data.user ...