Ordering by does not effectively filter out numbers

I am using the ng-repeat directive in my code.

<tr data-ng-repeat="list in vm.customer.lists | orderBy: list.id track by $index">
    <td>[[list.name]]</td>
    <td>[[list.locations.length]] Location<span data-ng-cloak data-ng-if="list.locations.length !== 1">s</span></td>
    <td><a data-ng-href="/#/locations/manage/list/edit/[[vm.customer.id]]/[[list.id]]" class="button expand">Manage Locations</a></td>
</tr>

I have a total of 3 lists in vm.customer.lists

I am attempting to sort these lists from least to greatest based on their list.id (1, 2, 3, etc.)

Could it be that I am not able to use the orderBy function with list?

Answer №1

It must be as follows:

<tr data-ng-repeat="list in vm.customer.lists | orderBy: 'id' ">

DEMO

var app = angular.module("app", []);
app.controller("ctrl", function($scope) {
  $scope.customer = 
      [{
      id: 4,
      name: 'sachin'
      
    }, {
      id: 1,
      name: 'Saurav'
     
    }, {
      id: 3,
      name: 'Dravid'
     
    }, {
      id: 2,
      name: 'Dhoni'
    
    }];
 
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="app" ng-controller="ctrl">  
    <li ng-repeat="list in customer | orderBy: 'id' track by $index">
     {{list.name}}
    </li>
 
</div>

Answer №2

Don't forget to add quotes in the filter

<tr data-ng-repeat="list in customer.lists | orderBy: 'id' track by $index">

var app = angular.module("app", []);
app.controller("ctrl", function($scope) {
  $scope.customer = {
    'lists': [{
      id: 4,
      name: 'T',
      locations: []
    }, {
      id: 1,
      name: 'S',
      locations: []
    }, {
      id: 3,
      name: 'R',
      locations: []
    }, {
      id: 2,
      name: 'O',
      locations: []
    }]
  };
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="app" ng-controller="ctrl">
  <table>
    <tr data-ng-repeat="list in customer.lists | orderBy: 'id' track by $index">
      <td>{{list.name}}</td>
      <td>{{list.locations.length}} Location<span data-ng-cloak data-ng-if="list.locations.length !== 1">s</span>
      </td>
      <td><a data-ng-href="/#/locations/manage/list/edit/[[vm.customer.id]]/[[list.id]]" class="button expand">Manage Locations</a>
      </td>
    </tr>
  </table>
</div>

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

Retrieve the individual content from a CKEditor instance using Ajax, even when there are multiple CKEditor instances with identical class names

Working with a PHP foreach loop that generates numerous data from the server also creates multiple CKEditor elements corresponding to specific data points. To have multiple CKEditor elements, the following code was used: <script> $(document).r ...

The HTML5 ondrop event finishes executing before zip.js completes its operations

I'm facing a problem where I need to use a datatransferitemlist asynchronously, which contradicts the functionality outlined in the specifications. According to the specs, access to the dataTransfer.items collection is restricted once the event ends. ...

Executing an HTTP request with JavaScript to interact with Salesforce

Looking to connect Salesforce with Recosence, an external system. The scenario involves Recosense pushing data to Salesforce for storage. I have successfully created a post HTTP service and tested it in Postman, which generates an access token and records ...

Creating unit tests for linked functions in Node.js using Jest

Hey there! I'm looking to test a function using Jest that involves token verification and requires 3 parameters. Here's the code for the function: const verifyToken = (req, res, next) => { // Checking for token in header or URL parameter ...

Overlap of columns within a nested flexbox arrangement

While working with React and Styled Components, I encountered a problem of elements overlapping each other: https://i.stack.imgur.com/RuCYu.png There are a few instances of overlap, including: The padding below the <ul> element is colliding with ...

Error encountered: EPERM when attempting to rename a directory in Node.js unexpectedly

There is a requirement for me to remove the Backup folder, rename the processor as Backup, create a Processor folder again, and send a response to the user. The code I am using for this task is as follows: fsExtra.remove('app/Backup', function(e ...

My React app experienced a severe crash when trying to render an animation in L

Currently, I am working on a React application that was set up using Vite. I recently incorporated an animation using Lottie, and although I was successful in implementing it, I encountered a problem when navigating between different pages of my applicati ...

Having difficulty sending emails with Nodemailer

This is a simple example showcasing the usage of Nodemailer library. var http = require('http'); var port = process.env.PORT || 8080; var async = require('async'); var nodemailer = require('nodemailer'); // Creating a transp ...

Transform Json data into CSV file format with customized headers and formatting

I have a function in my code that fetches JSON data from an endpoint and converts it into a CSV file. Is there a way for me to specify specific headers and the order of columns I want in this CSV file? function downloadJSONAsCSV(endpoint) { // Fetch J ...

What is the process for retrieving a variable within the link section of your Angular Js directive?

Can someone help me with creating a directive that can automatically generate the current year for a copyright notice? I'm struggling to figure out how to access the year variable in the link function of the directive. I have tried several methods, bu ...

A guide on transmitting JSON information from ASP.NET MVC 5 to Angular on the client side, specifically in the context of authentication

When the user is authenticated, I need to redirect to a different view and send JSON data containing the userid and username for AngularJS to use. The redirection works fine, but I'm unsure how to pass the user information as JSON to the client-side. ...

Display the worth in a pop-up box

I am looking to display the form value in a pop-up window that opens after clicking the submit button. How can I achieve this? Here is my form: <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> &l ...

What is the best way to execute AJAX requests in a loop synchronously while ensuring that each request is completed

I am looking to implement an AJAX loop where each call must finish before moving on to the next iteration. for (var i = 1; i < songs.length; i++) { getJson('get_song/' + i).done(function(e) { var song = JSON.parse(e); addSongToPlayl ...

Incorporating mousewheel functionality by utilizing DOMmouseScroll and mousewheel to trigger functions

Looking to create a function that triggers other functions based on the direction of mousewheel movement, but unsure how to proceed. Initially coded for mousewheel event, however, Firefox does not support this event. Need to find a way to incorporate DOMm ...

Is it possible to define a variable within a JavaScript function and then access it outside of the function?

I have a Node.js application where I need to define a variable inside a function and access its value outside the function as well. Can someone provide guidance on how to achieve this in my code? var readline = require('readline'); var rl = read ...

Welcome to the awe-inspiring universe of Typescript, where the harmonious combination of

I have a question that may seem basic, but I need some guidance. So I have this element in my HTML template: <a href=# data-bind="click: $parent.test">«</a> And in my Typescript file, I have the following code: public test() { alert( ...

I am currently facing a challenge in React Highcharts where I am unable to remove and redraw the graph easily

Having an issue where I can't remove and redraw the chart in my React Highchart project. I've been unable to find a solution for this problem. Here is the code snippet: import { useState, useEffect, useRef } from "react"; import Highch ...

Transform an image into Base64 format by effortlessly dragging and dropping

I am looking to add a specific feature to my website that can be implemented solely on the client side using JavaScript or any JavaScript library. The requirement is to allow users to drag and drop an image from their local machine directly into the brows ...

Jquery and CSS3 come together in the immersive 3D exhibit chamber

Recently, I stumbled upon an amazing 3D image gallery example created using jQuery and CSS3. http://tympanus.net/codrops/2013/01/15/3d-image-gallery-room/ Excited by the concept, I attempted to incorporate a zoom effect (triggered every time a user clic ...

Tracking triggered JavaScript events (across all browsers)

Although this query may have been addressed previously, the responses mostly pertain to browser-specific techniques. My inquiry is straightforward: Is there a method to observe all triggered events (specifically the fired event and the corresponding elemen ...