How do I sort a drop down list in alphabetical order in Angularjs?

  • Learn
    • Tutorial
    • FAQ
    • Videos
    • Free Course
    • Case Studies
  • Develop
    • Developer Guide
    • API Reference
    • Error Reference
    • Contribute
    • Seed App project template
    • GitHub
    • Changelog
    • Download
  • Discuss
    • Blog
    • Twitter
    • Google+
    • Feature & Bug Tracker
    • Mailing List
    • IRC
    • Gitter

Angular7- Sort in Alphabetical Order- Select Dropdown options

1 year ago

I have a list of commodity items where i have to sort all IDM items in alphabetical order and below that DM items in alphabetical order , rite now my code displays like below order:but i want IDM to display first and next DM

**WRONG:** DM-Air DM-BELL DM-CEL IDM-AIR IDM-BELL IDM-CELL **CORRECT** IDM-AIR IDM-BELL IDM-CELL DM-Air DM-BELL DM-CEL

my code is

this.supplier.getCommoditiesFamilyList().subscribe( (data: any) => { this.commoditiesFamilyList = data; this.commoditiesFamilyList.sort(this.commoditySortByName); }, this.supplier.getCommoditiesFamilyList(id).subscribe( data => { this.commoditiesFamilyList = data; this.commoditiesFamilyList.sort(this.commoditySortByName); }, [![this.subscriberLevelId = id; this.supplier.getCommoditiesFamilyList(id).subscribe( data => { this.commoditiesFamilyList = data; this.commoditiesFamilyList.sort(this.commoditySortByName); },][1]][1] public commoditySortByName(a, b) { if (a.name < b.name) { return -1; } if (a.name > b.name) { return 1; } return 0; } }

Source: Angular Questions

Share this:

  • Angular7- Sort Select Dropdown options in Alphabetical Order
  • October 8, 2020
  • In "angular"
  • Javascript/Angular 7 Sort *ngFor Options in Alphabetical Order
  • October 8, 2020
  • In "angular"
  • how to display array of object contents alphabetical order starting with small letter to capital in angularjs
  • February 7, 2019
  • In "javascript"
Categories: angular, javascript, typescript
Tags: angular, javascript, typescript
Leave a Comment

AngularJS orderBy Filter

❮ AngularJS Reference

Example

Display the items alphabetically:

<div ng-app="myApp" ng-controller="orderCtrl">

<ul>
<li ng-repeat="x in cars | orderBy">{{x}}</li>
</ul>

</div>

<script>
var app = angular.module('myApp', []);
app.controller('orderCtrl', function($scope) {
$scope.cars = ["Dodge", "Fiat", "Audi", "Volvo", "BMW", "Ford"];
});
</script>
Try it Yourself »

How TO - Sort a List

❮ Previous Next ❯

Learn how to sort an HTML list, using JavaScript.

Click the button to sort the list alphabetically:

Sort
  • Oslo
  • Stockholm
  • Helsinki
  • Berlin
  • Rome
  • Madrid

Try it Yourself »

Video liên quan

Postingan terbaru

LIHAT SEMUA