AngularJS helps to organize data and manipulate information within a single page,

In need of assistance with a code that retrieves employees from a controller and applies pagination while filtering records. The issue arises when attempting to filter from a page other than the first, as it does not display any filtered results.

The code in question is as follows:

-filter.js

angular.module('MyApp', ['ui.bootstrap']).controller('MyController', function ($scope, EmployeesService) {
    $scope.Employees = null;
    $scope.currentPage = 1; 
    $scope.pageSize = 2;
    $scope.maxSize = 100;


    EmployeesService.GetEmployees().then(function (d) {
        $scope.Employees = d.data; // Success

    }, function () {
        alert('Failed'); // Failed
    })
})

.service('EmployeesService', function ($http) {
    var service = {};
    service.GetEmployees = function () {
        return $http.get('/Employees/GetEmployees');
    }
    return service;
})
.filter('start', function () {
    return function (input, start) {
        if (!input || !input.length) { return; }
        start = +start;
        return input.slice(start);

    };
});

-Index.cshtml

<div ng-app="MyApp">
    <div ng-controller="MyController">

        <input type="text" ng-model="filterText" name="searchString" placeholder="Search for names.." class="form-control"><br />

        <div ng-repeat="emp in Employees |orderBy: 'employeeName'| filter: filterText | start: (currentPage-1) * pageSize | limitTo: pageSize"
             class="alert alert-warning col-md-12">    

            <span ng-bind="emp.employeeName"></span> <b>:</b>
            <span ng-bind="emp.employeePhoneNumber"></span>

        </div>
        <pagination ng-model="currentPage" total-items="Employees.length" items-per-page="pageSize"></pagination>
    </div>
</div>

Your help is greatly appreciated.

Apologies for the delay. Here is the functioning JSFiddle:

https://jsfiddle.net/neslisahozdemir/khbbbe47/4/

Answer №1

If you reorganize the sequence of filters, your query should be resolved.

Give this a try:

 <tr ng-repeat="emp in Employees  | filter: filterText|orderBy: 'employeeName' |start: (currentPage-1) * pageSize | limitTo: pageSize" class="alert alert-warning col-md-12">

Currently, the filter works on a page-by-page basis (if you search for "C", you'll find one record on pages 1 and 2).

By changing the order of filters, you'll see all data on the same page (2 records on page 1) when filtering for "C".

Check out the updated fiddle.

I hope this solution helps!

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

Using PHP and JavaScript to enhance functionality around a hyperlink

I am trying to incorporate a small piece of Javascript on my website to ensure user confirmation. While I have successfully used the 'onclick' function with buttons, I am facing difficulty implementing it on a link. Here is the link in question: ...

What could be causing JQuery to concatenate the string twice?

Looking for a way to trigger the playback of a YouTube video embedded within a div named #youtubecontainer after a button click with the class .playbutton. The video itself is embedded as an iframe within the specified div. One way to make this work is b ...

Deciphering a Base64 image string in order to convert it back into a file for uploading to Parse

Incorporating CropperJS into a Node.js solution poses a challenge for me as I aim to convert the returned Base64 string into a file format in order to upload it. The goal is to maintain functionality while utilizing the file type as a parameter. Despite m ...

Encountering a problem in Angular 2 when trying to pass undefined variables between components while fetching data from

My approach involves making a single API call and storing the response in a global variable within my Service. I then utilize two helper functions to share and manipulate this value between parent and child components. repairs.service.ts public myItems:a ...

Guide on executing a sequence of animations with the help of promises

In my current project, I am creating a Rubik's cube animation using three.js. The main challenge I am facing is implementing a function to shuffle the cube smoothly. So far, I have successfully developed functions to animate single moves, such as rot ...

Create random animations with the click of a button using Vue.js

I have three different lottie player json animation files - congratulations1.json, congratulations2.json and congratulations3.json. Each animation file is configured as follows: congratulations1: <lottie-player v-if="showPlayer1" ...

A guide on mounting dynamically added tags

Within my webpage, I have integrated two files - (dialog.tag) and (radio.tag), which are compiled and mounted using the command riot.mount('*') I am currently attempting to dynamically insert DOM elements into the existing riot tag (dialog): &l ...

NodeJS has a knack for replying even before the function has completed

Struggling with a NodeJS and Express API for a school project. The getAuthUserId function is not working as expected. It decodes the JWT token to retrieve the user Id from the mongoDB server. However, when calling this function in a REST call "/user/authT ...

Is there an issue with $scope variable overriding on ng-blur? The ng-model isn't updating with the $scope variable in

I am currently developing a web app using ionic/angular where users have the option to select a location either from a Google map displayed in a modal or through a Google Map autocomplete searchbox. To enhance the user experience, I want the address chose ...

Prevent refreshing Google Maps when changing routes in AngularJS

Utilizing a Google map as the background for my website adds a unique visual element to the data displayed on different routes. However, I have encountered an issue where the map reloads with every route change, resulting in an unsightly flash of white tha ...

Attempting to pinpoint a nested JSON object within multiple layers of objects in ReactJS

Trying to map over a JSON blob and unsure of how to target the array within "text/plain" for individual cell parsing. { "pdns": [ { "id":6, "code":"\nfrom trutils.spark import pdns\nimport json\ndf = pdns.query(val ...

What is the best method for retrieving data through an ajax call in my modular JavaScript setup?

Working with a basic modular JavaScript structure, my goal is to request a random quote from an API and display it on an HTML page using Mustache.js. I previously achieved this without the modular approach, but now I'm attempting it in a more structur ...

Ways to retrieve a field from various objects contained within an array

My array is empty and named $scope.mobData=[]; After using $http.get(..), I successfully push 10 JSON objects into the array, each with 7 data points. However, I only need to display two fields from each object: brandCode and brandName. Even though these ...

What could be the reason for the Mongoose findAll function causing a 500 error to occur?

My model / Schema has a working create method, but the "all" method is causing a 500 error. var mongoose = require('mongoose'); var Schema = mongoose.Schema; var DiSchema = new mongoose.Schema({ name: { type: String, lowercase: true , require ...

How can I remove all javascript code from a string using PHP?

Recently, I came across some PHP code that raised concerns: $mystr = "<script>window.onload = function(){console.log('Hi')}</script>"; $mystr .= "<div onmouseover='alert('Hi')'></div"; The goal here is t ...

Top method for determining available space for images positioned randomly within a specified area

Currently, I am utilizing HTML's Canvas tag to design a word cloud that is randomly generated. My main focus is on finding the most effective way to determine where there is sufficient blank space within a specified area to accommodate a word. At the ...

Triggering an event through a shared messaging service to update the content of a component

I'm looking for a simple example that will help me understand how I can change the message displayed in my component. I want to trigger a confirmation box with *ngIf and once I confirm the change, I want the original message to be replaced with a new ...

How to turn off spin buttons for input type=“number” in AngularJS when using webkit

Although similar advice can be found for 'normal' Bootstrap, the solution may not be the same for AngularJS. input[type=number]::-webkit-inner-spin-button, input[type=number]::-webkit-outer-spin-button { -webkit-appearance: none; margin: ...

Endless loop in XMLHttpRequest()

I am trying to use Ajax in the code snippet below to continuously retrieve a PHP query result until it reaches "6". The code seems to be functioning correctly, but once the result is "6", the script does not stop running. Instead, my CPU fan starts making ...

When integrating React with Tawk, the user's name and email are automatically encoded before being sent

My code within the componentDidMount() function initializes a widget popup when the page loads. It then sets the name and email using parameters received from the previous page. const fullName = this.state.data[0]; console.log(fullName); const e ...