What is the best way to determine the total number of records returned on the current page while using pagination with Angular?

I am currently displaying 2 records per page out of a total of 10 pages. I would like the header to display the total items in this format: 1-2 of 10, indicating record numbers 1 and 2 out of 10. When I click the next button, it should show me records 3-4 of 10. I have not been able to find any guidance on how to achieve this from Angular tutorials. Can someone please help me with this?

Below is my pagination code in HTML:

<pagination page="currentPage" max-size="maxSize" total-items="totalItems"
items-per-page="entryLimit" boundary-links="true" rotate="false" style="cursor:pointer">
</pagination>

And here is the controller logic being used:

$scope.currentPage = 1;
$scope.maxSize = 2;
$scope.totalLeadItems = $scope.finalLeadData.dataval;
$scope.totalItems = $scope.finalLeadData.dataval.length;
$scope.entryLimit = 2; // items per page
$scope.noOfPages = Math.ceil($scope.totalItems / $scope.entryLimit);

$scope.search = function (item) {
//console.log(item.LEAD_NM);
return !!((angular.lowercase(item.LEAD_NM).indexOf($scope.search.LEAD || '') !== -1 || angular.lowercase(item.LEAD_MBL).indexOf($scope.search.LEAD || '') !== -1)); };

//$watch search to update pagination
$scope.$watch('search.LEAD', function (newVal) {
$scope.filtered = filterFilter($scope.finalLeadData.dataval, newVal);
$scope.totalItems = $scope.filtered.length;
$scope.noOfPages = Math.ceil($scope.totalItems / $scope.entryLimit);
$scope.currentPage = 1;
}, true);
});

Answer №1

To perform this computation within the DOM, follow these steps:

{{ currentPage * entryLimit - 1 }} - {{ currentPage * entryLimit }} of {{ totalLeadItems.length }}

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

Marshaling a payload in Groovy at a snail's pace

I am currently working on an Angular/Groovy Application and facing slow performance while marshaling a payload in the backend (Groovy). The process takes a significant amount of time to complete, send the data to the frontend, and render it. In the backen ...

Load resources asynchronously with OcLazyLoad before the controller is initialized

I am looking to make an HTTP call to my webservice using a $resource provider and then inject the result into the controller. To achieve this, I have written the following code snippet with thoughts on using OcLazyLoad: First, load the service Make the H ...

Calculate the pixel distance between various divs by measuring the horizontal distance from the left border to the right

I am trying to find the precise distance between : #main div left edge to the first div with class="b" between the first div with class="b" to the second div with class="b" It's worth noting that the divs may be arranged randomly and could have fix ...

Is there a way to determine whether a number is lesser, greater, or falls within a specific range of values

Is there a more concise and readable way to write a function that checks if a given number is smaller, larger, or between two other numbers? The function should return NaN if any of the input parameters are not numbers. function order(num, a, b) { if ...

How to properly utilize ng-repeat and ng-switch in AngularJS?

Scenario: I have encountered multiple queries similar to mine, but I am struggling to find a solution to my specific question. In my code, I am working with an array of objects: $scope.messages = [obj1, obj2, ...]; Each object in the array follows this ...

Tips for locating the ID of an object in an array when only one attribute in the "child" array is known

Seeking assistance in creating a JavaScript function that efficiently determines the id of the "parent" object based on the code of a "child" object from the dataArray. For example: getIdParent("240#code") -> should return "1" [ { id: 0, ...

Discover the power of Mapbox Geocoding

After implementing Mapbox's Geocoder Contro, I am thrilled with how well it is working. One thing that I am trying to figure out is how to display a marker at the exact location of the address that was searched for. Below you can see the code snippet ...

Enable the execution of a function only once a specific period of time has elapsed

Here's the scenario I'm dealing with: In a fun group chat with my friends, I created a giphy bot that responds to /giphy [terms] messages by posting the top result for those terms. However, my friends started abusing it by spamming the chat. To ...

javascript identifying a variable within location.href

Within my JavaScript code, there is a variable that holds a value: var selectedItemId = null; // the value is assigned by another function Next, there is a function defined like this: function editLink() { location.href = /*[[@{/supplycontracts/edit ...

Communicate through PHP and JavaScript chat to display HTML content in the chat window

I have been attempting to display HTML output in the chat window but instead, it is showing the HTML code. Here are the two files involved in the chat system: chat.js `function chatHeartbeat(){ var itemsfound = 0; if (windowFocus == false) { var ...

What is the method to extract information from the provided URL?

Hello, I am looking to retrieve system requirements data from . How can I achieve this using JS or react? ...

A guide on dynamically altering text upon hovering over an element using Vue.js

On my website, I have the following HTML code: <div class="greetings"> <img @mouseover="hover='A'" @mouseleave="hover=''" src="a.png" alt="A" /> <img @mouseover="hover='B'" @mouseleave="hover=''" ...

Issue with AngularJS ng-repeat and ng-show not functioning properly upon page reload

Hey there! I'm facing an issue with my web application that I built using AngularJS and Spring. This platform allows users to post messages, and I've written the following code in my Angular controller. <div class="row" ng-repeat="message in ...

Issue encountered while attempting to execute the npm run dev command for launching a Next.js application

Error Message in the Terminal: $ npm run dev npm ERR! code ENOENT npm ERR! syscall open npm ERR! path C:\Users\HARSH KUMAR\Desktop\Amazon watchdog\package.json npm ERR! errno -4058 npm ERR! enoent Could not read package.json: Error ...

Creating a grid layout that activates an image when clicked using JavaScript

I've successfully implemented a gridview with an image column, but I'm looking to enhance the functionality. Specifically, I want to enlarge the clicked image and bring it into focus on the screen. I've managed to achieve this when the image ...

Challenges with implementing speech recognition within a React component's state

I've encountered an issue with the React library react-speech-recognition. When trying to modify the newContent state within useEffect, it ends up printing as undefined. Additionally, I'm facing a similar problem when attempting to update the sta ...

AngularJS does not seem to be functioning properly within the MVC PartialView

When working with my Index.cshtml file and calling a PartialView while using angularJS, I encountered an issue... Here is my Index.cshtml: <!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width" /> ...

Determine if the content has finished loading once it has been added using JavaScript

I am currently working on a project in pure JavaScript that involves implementing a feature similar to Facebook's message loading. This means that when you scroll to the end of the page, new HTML content is loaded and added to the page. The additional ...

header that sticks with irregular motion

Currently in the process of designing a website, I've run into an issue where whenever I scroll with my sticky header, the page automatically jumps to the bottom of the next element. Does anyone have any insights on what might be causing this odd beha ...

updating react state based on filtered redux properties

Just starting out with react & redux and running into some issues with filtering insights (articles, case studies, reports). My goal is to filter by industry, but I'm struggling to update the state with the filtered insights. InsightsPage.js con ...