Status 'ACTIVE' not filtering as anticipated in the system

Display the list of users based on the selected status using the following JSP code:

<table>
    <thead>
      <tr>
        <th>Aggregate</th>
        <th>User id</th>
        <th>First Name</th>
        <th>Last Name</th>
        <th>Phone Number</th>
        <th>Email</th>
        <th class="text-center">Status</th>
      </tr>
    </thead>

    <tbody >

        <tr>
            <td><input type="text" class="form-control" ng-model="search.agId" /></td>
            <td><input type="text" class="form-control" ng-model="search.id" /></td>
            <td><input type="text" class="form-control" ng-model="search.firstName" /></td>
            <td><input type="text" class="form-control" ng-model="search.lastName" /></td>
            <td><input type="text" class="form-control" ng-model="search.mobileNo" /></td>
            <td><input type="text" class="form-control" ng-model="search.emailId" /></td>
            <td>
                <select class="form-control" ng-model="search.status">
                    <option value=""> Select </option>
                    <option value="ACTIVE"> Active </option>
                    <option value="INACTIVE"> In Active </option>
                    <option value="B"> Blocked </option>
                </select>
            </td>
        </tr>


        <tr ng-repeat="userone in filtereddata = (users.data | filter:search)">
            <td>{{ userone.agId }}</td>
            <td>{{ userone.id }}</td>
            <td>{{ userone.firstName }}</td>
            <td>{{ userone.lastName }}</td>
            <td>{{ userone.mobileNo }}</td>
            <td>{{ userone.emailId }}</td>
            <td class="text-center" ng-switch on="userone.status">
                <span class="inac label label-success" ng-switch-when="ACTIVE">Active</span> 
                <span class="inac label label-danger" ng-switch-when="INACTIVE">In Active</span> 
                <span class="inac label label-danger" ng-switch-when="B">Blocked</span>
            </td>
        </tr>

    </tbody>
</table>

Controller JS code

$scope.$watch('search', function (newVal, oldVal) {
            $scope.filtered = filterFilter($scope.users.data, newVal);

            console.log($scope.filtered);

            $scope.bigTotalItems = (typeof $scope.filtered == 'undefined' ) ? 0 : $scope.filtered.length;
            $scope.noOfPages = Math.ceil($scope.bigTotalItems/$scope.entryLimit);
            $scope.currentPage = 1;
        }, true);

The code works for INACTIVE and blocked users (i.e. B), however, it shows all users with ACTIVE and INACTIVE statuses when Active is selected.

In the Controller JS code, there is a simple console.log($scope.filtered) that returns both ACTIVE and INACTIVE members in the filtered data when Active is chosen. It works fine for other selections.

If more information is required, feel free to ask

Answer №1

angular.module('test', []).controller('Test', Test);

function Test($scope, $filter) {
  $scope.data = [{
    name: 'apple',
    status: 'inactive'
  }, {
    name: 'banana',
    status: 'active'
  }, {
    name: 'grape',
    status: 'deleted'
  }, {
    name: 'orange',
    status: 'inactive'
  }, {
    name: 'pear',
    status: 'deleted'
  }, {
    name: 'watermelon',
    status: 'active'
  }]
  
  $scope.filter = function(actual, expected) {
    if (expected == '') return true;
    
    return angular.equals(actual, expected);
  }
  
  $scope.$watch('search', function(newVal) {
    $scope.filtered = $filter('filter')($scope.data, newVal, $scope.filter);
  });
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.min.js"></script>
<div ng-app='test' ng-controller='Test'>
  Search:
  <select ng-model="search">
    <option value="">Select</option>
    <option value="active">Active</option>
    <option value="inactive">Inactive</option>
    <option value="deleted">Deleted</option>
  </select>
  <hr>
  <div ng-repeat="item in data | filter:search:filter">
    {{item.name}} - {{item.status}}
  </div>
  <hr>
  <div ng-repeat="item in filtered">
    {{item.name}} - {{item.status}}
  </div>
</div>

After reviewing the information on the official AngularJS API documentation, it seems that it is possible to ensure strict comparison by providing a value of true as the third parameter.

<tr ng-repeat="userone in filtereddata = (users.data | filter:search:true)">

If you want accurate results in your controller, make sure to include the third parameter.

$scope.filtered = filterFilter($scope.users.data, newVal, $scope.filter);

Edit: To address the issue of empty results when selecting an empty filter, we will need to implement a custom filtering function. The code has been updated accordingly.

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 is the best way to create an arrow that tracks the browser window, but only goes as far as the end of its designated container

Currently, I am facing a challenge in implementing a scroll down arrow. While this is typically a simple task, it has proven to be a bit more complex this time around. The complexity arises from the fact that my customer desires a homepage with an image of ...

Select dates within a range using jQuery UI datepicker

Looking to implement the jQuery UI datepicker on my asp.net aspx page, I aim to enable range selection and include an OK button on the calendar. After discovering a tutorial demonstrating this functionality at the following link: jQuery UI Datepicker - Ra ...

How to unbind an AngularJS directive without causing scope destruction

Is there a way to completely unbind all the values from a directive template without destroying its scope? I typically use scope.$destroy for this task, but in this specific case I can't destroy the scope because it inherits from the parent and I sti ...

angular - what distinguishes between these two .factory functions?

sellingApp.factory('SellingService', ['$http', function ($http) { return { CheckStatus: CheckStatus }; function CheckStatus() { console.log(breeze); return $http({ method: 'GET' ...

The JavaScript operator that functions in a manner akin to the SQL "like"

I am working on a jQuery function that needs to perform like the "like" operator. Can anyone help me achieve this? Your assistance is greatly appreciated. The function currently only works if I search for the whole word, for example: var vsearch = "home" ...

Issue with JavaScript ScrollTop

Simply put, I am trying to determine the total scroll size for a text area in a unit that scrollTop can align with. However, I am at a loss on how to do so. I've tried scrollHeight and various other methods without success. Any advice or suggestions ...

Encountering a problem with importing a component containing a local image from another package in Next

I am facing an issue with my monorepo which includes a NextJS project and a React library. My goal is to import components from the React project into the NextJS project. Everything seems to be working fine until I try to import a component that contains a ...

Creating Interactive Graphs with HTML and JavaScript: A Guide to Dynamic Graph Drawing

I am seeking to create a dynamic graph using standard HTML, JavaScript, and jQuery (excluding HTML5). The nodes will be represented by divs with specific contents, connected by lines such as horizontal and vertical. The ability to add and remove nodes dyn ...

Update the variable obtained from the user input and insert it into a new container depending on the input value

In reference to my previous inquiries, I refrain from adding more details to avoid confusion since it already received numerous responses. While I can successfully retrieve input from a text field with the ID 'test' and display it in the 'r ...

"Receiving a 404 error when making an AngularJS $http post request to a

Here is a question that I could not find an answer to elsewhere. I am new to AngularJS and NodeJS, after completing some tutorials, I am trying to put things together. When working with NodeJS, if I have code like this: app.get('/db-get-extra-bookin ...

What is the best approach for integrating HTML and JavaScript code into Flutter mobile platforms?

For the past 4 months, I've been immersing myself in Flutter without any prior experience in Javascript. My goal is to utilize the Soundcloud HTTP API to create a user-interactive app. However, I've hit a roadblock when it comes to integrating JS ...

Explore the power of Infinity.js for optimizing the rendering of large HTML tables, complete with a detailed example using prototype

Is there a way to efficiently load/render large html tables without compromising performance, especially in Internet Explorer? I recently came across a plugin in prototype.js (https://github.com/jbrantly/bigtable/, post: , demo:) that addresses this issue ...

Execute the While loop covertly

I am working with a JavaScript application that is Angular-based. It runs a while loop when a user clicks a button and continues until a certain number is reached, at which point it ends. However, I am facing an issue where I cannot interact with other e ...

processing an array using ajax form submission

Trying to manage an array that is returned from a PHP file after submitting form data. The value of the data after form submission is = ARRAY but I am unable to use this array in any way. Any suggestions on how to handle this array? Javascript: $(&apo ...

Managing the size of personalized shapes in Three.js

I need help with a custom object that represents a frame created by subtracting two meshes. generateFrame (width, height, depth) { const frameMesh = new THREE.Mesh(new THREE.BoxGeometry(1, 1, 1)); frameMesh.scale.set(width, height, depth); c ...

Guide on adding a post type via the command line: Issue encountered - Anticipated POST console HTML error

Facing Error: EXPECTED POST in JQuery Ajax Call Encountering the same issue as mentioned in the provided link. The need is to switch from GET to POST, but direct alteration of ajax code is not feasible. It must be done dynamically using JavaScript through ...

The functionality of using an Ajax call to invoke a php function on the same page is not functioning correctly

I am facing an issue where Ajax is not working in the same PHP file as the PHP function I want to call. My goal is to have a button that, when pressed, will trigger the function without reloading the page. I have placed my Ajax script at the bottom and the ...

Is it necessary to create a Node endpoint for each item in the array?

My current tech stack includes ExpressJs, NodeJs, and AngularJs. Imagine I have an array containing various objects representing grocery store accounts and the amounts owed to them by the bank. [{ account: 1, amount: 2.33 }, { account: 2, amount: 5.99 ...

I'm encountering a situation where the displayName is coming up as null during authentication triggers

Why am I receiving null when trying to use user data in the authentication trigger for my code? exports.sendWelcomeMessage = functions.auth.user().onCreate((user) => { const name = user.displayName; console.log(name); return null; }) ...

Does this task require a high amount of CPU resources for Node.js on the back-end?

I am currently developing an Android app and I am faced with a decision on whether to utilize node.js or PHP for the back-end. The task at hand involves users inputting query parameters, such as zip codes, which are then used to perform database queries ...