Популярное

Музыка Кино и Анимация Автомобили Животные Спорт Путешествия Игры Юмор

Интересные видео

2025 Сериалы Трейлеры Новости Как сделать Видеоуроки Diy своими руками

Топ запросов

смотреть а4 schoolboy runaway турецкий сериал смотреть мультфильмы эдисон
dTub
Скачать

Sorting data in AngularJS

Автор: kudvenkat

Загружено: 2015-11-07

Просмотров: 333362

Описание:

angularjs order data
angularjs orderby filter example
angularjs ng-repeat orderby example
angularjs filter orderby date
angularjs orderby reverse
angularjs orderby ascending
angularjs filter orderby descending

Healthy diet is very important both for the body and mind. If you like Aarvi Kitchen recipes, please support by sharing, subscribing and liking our YouTube channel. Hope you can help.
   / @aarvikitchen5572  

In this video we will discuss how to implement sorting in AngularJS. This is continuation to Part 8. Please watch Part 8 from AngularJS tutorial for beginners before proceeding.

To sort the data in Angular
1. Use orderBy filter
{{ orderBy_expression | orderBy : expression : reverse}}
Example : ng-repeat="employee in employees | orderBy:'salary':false"
2. To sort in ascending order, set reverse to false
3. To sort in descending order, set reverse to true
4. You can also use + and - to sort in ascending and descending order respectively
Example : ng-repeat="employee in employees | orderBy:'+salary'"

Let us understand sorting data with an example.

The dropdownlist shows the columns and the direction we want to sort
When a dropdownlist item is selected, the table data should be sorted by the selected column

Script.js : The controller function builds the model. Also sortColumn property is added to the $scope object. Notice sortColumn property is initialized to name. This ensures that the data is sorted by name column in ascending order, when the form first loads.

var app = angular
.module("myModule", [])
.controller("myController", function ($scope) {

var employees = [
{ name: "Ben", dateOfBirth : new Date("November 23, 1980"), gender: "Male", salary: 55000 },
{ name: "Sara", dateOfBirth: new Date("May 05, 1970"), gender: "Female", salary: 68000 },
{ name: "Mark", dateOfBirth: new Date("August 15, 1974"), gender: "Male", salary: 57000 },
{ name: "Pam", dateOfBirth: new Date("October 27, 1979"), gender: "Female", salary: 53000 },
{ name: "Todd", dateOfBirth: new Date("December 30, 1983"), gender: "Male", salary: 60000 }
];

$scope.employees = employees;
$scope.sortColumn = "name";
});

HtmlPage1.html : The select element, has the list of columns by which the data should be sorted. + and - symbols control the sort direction. When the form initially loads notice that the data is sorted by name column in ascending order, and name option is automatically selected in the select element. Notice the orderBy filter is using the sortColumn property that is attached to the $scope object. When the selection in the select element changes, the sortColumn property of the $scope object will be updated automatically with the selected value, and in turn the updated value is used by the orderBy filter to sort the data.

[!DOCTYPE html]
[html xmlns="http://www.w3.org/1999/xhtml"]
[head]
[title][/title]
[script src="Scripts/angular.min.js"][/script]
[script src="Scripts/Script.js"][/script]
[link href="Styles.css" rel="stylesheet" /]
[/head]
[body ng-app="myModule"]
[div ng-controller="myController"]
Sort By :
[select ng-model="sortColumn"]
[option value="name"]Name ASC[/option]
[option value="+dateOfBirth"]Date of Birth ASC[/option]
[option value="+gender"]Gender ASC[/option]
[option value="-salary"]Salary DESC[/option]
[/select]
[br /][br /]
[table]
[thead]
[tr]
[th]Name[/th]
[th]Date of Birth[/th]
[th]Gender[/th]
[th]Salary[/th]
[/tr]
[/thead]
[tbody]
[tr ng-repeat="employee in employees | orderBy:sortColumn"]
[td]
{{ employee.name }}
[/td]
[td]
{{ employee.dateOfBirth | date:"dd/MM/yyyy" }}
[/td]
[td]
{{ employee.gender }}
[/td]
[td]
{{ employee.salary }}
[/td]
[/tr]
[/tbody]
[/table]
[/div]
[/body]
[/html]

Styles.css : CSS styles to make the form look pretty.

body {
font-family: Arial;
}

table {
border-collapse: collapse;
}

td {
border: 1px solid black;
padding: 5px;
}

th {
border: 1px solid black;
padding: 5px;
text-align: left;
}

Link for all dot net and sql server video tutorial playlists
https://www.youtube.com/user/kudvenka...

Link for slides, code samples and text version of the video
http://csharp-video-tutorials.blogspo...

Sorting data in AngularJS

Поделиться в:

Доступные форматы для скачивания:

Скачать видео mp4

  • Информация по загрузке:

Скачать аудио mp3

Похожие видео

AngularJS sort rows by table header

AngularJS sort rows by table header

AngularJS filters

AngularJS filters

Angularjs filter by multiple properties

Angularjs filter by multiple properties

Controllers in AngularJS

Controllers in AngularJS

НДС 22% не поможет. Кризис регионов России | Кузбасс — банкрот, сокращения на Урале, инфляция в ЖКХ

НДС 22% не поможет. Кризис регионов России | Кузбасс — банкрот, сокращения на Урале, инфляция в ЖКХ

Уязвимости в современных JavaScript-фреймворках на примере React, Vue и Angular / А. Важинская

Уязвимости в современных JavaScript-фреймворках на примере React, Vue и Angular / А. Важинская

Hi-Fi - TOP 20 - Лучшие песни

Hi-Fi - TOP 20 - Лучшие песни

AngularJS tutorial for beginners

AngularJS tutorial for beginners

Декораторы Python — наглядное объяснение

Декораторы Python — наглядное объяснение

⚡️ Путин предложил Западу сделку || НАТО поставили перед условием

⚡️ Путин предложил Западу сделку || НАТО поставили перед условием

Consuming ASP NET Web Service in AngularJS using $http

Consuming ASP NET Web Service in AngularJS using $http

Что такое TCP/IP: Объясняем на пальцах

Что такое TCP/IP: Объясняем на пальцах

Понимание Active Directory и групповой политики

Понимание Active Directory и групповой политики

Кто пишет код лучше всех? Сравнил GPT‑5.2, Opus 4.5, Sonnet 4.5, Gemini 3, Qwen 3 Max, Kimi, GLM

Кто пишет код лучше всех? Сравнил GPT‑5.2, Opus 4.5, Sonnet 4.5, Gemini 3, Qwen 3 Max, Kimi, GLM

Ранкс объяснил, что опаснее посягательств Трампа на Гренландию.

Ранкс объяснил, что опаснее посягательств Трампа на Гренландию. "Мы, к сожалению, дернули рубильник"

AngularJS routeparams example

AngularJS routeparams example

AngularJS ng repeat directive

AngularJS ng repeat directive

Филипп Робертс: Что за чертовщина такая event loop? | JSConf EU 2014

Филипп Робертс: Что за чертовщина такая event loop? | JSConf EU 2014

Но что такое нейронная сеть? | Глава 1. Глубокое обучение

Но что такое нейронная сеть? | Глава 1. Глубокое обучение

Хватит кодить, пора начинать проектировать: Google Antigravity + Cloud Run

Хватит кодить, пора начинать проектировать: Google Antigravity + Cloud Run

© 2025 dtub. Все права защищены.



  • Контакты
  • О нас
  • Политика конфиденциальности



Контакты для правообладателей: infodtube@gmail.com