- The data will be sorted when clicking on one of the columns headers.
- The user should be able to sort in both the directions (ascending and descending).
- Clicking on the column for the first time will sort the data in ascending order.
- on the same column again will sort data in descending order.
- An arrow (up/down) will be displayed next to the column showing the sort column and direction.
- The data will be sorted according to the selected option in the ddl.
orderByfilter allow the array sorting.
- Some columns will be sorted descending and others will be sorted ascending, as:
- minus sign (-) allows the descending sorting.
- plus sign (+) allows the ascending sorting. It is the default.
In the following example:
We will display the students information in the following format:
- First name: Uppercase
- Last name: Uppercase
- Gender: Uppercase
- Spec: Lowercase
- Level: Uppercase
- Date of Birth (DOB): Date Format
You can refer to AngularJs Date Format Reference to now more about date format.
– Filters can do the following:
- Filter data
– To apply filter, use pipe (|) character.
– Filters can be used with a directive or binding expression.
– The following is a list of AngularJs filters (Source: AngularJs Filters )
We recommend you to review a simple example of ng-repeat directive before reading this post.
In the following example:
- Using AngularJs controller and module, we create an array of students.
- Each student has (first name, last name, gender, specialization, and level) information.
- Then, we display the students information in an html page.
- To display each student information, we use “ng-repeat” directive.
- Using the AngularJs two way data binding, when you type the student information in the input field (Enter student information part), the value will immediately be displayed on the view part (View student information part).
- Now, we don’t need any custom code to move data from the model to the view or from the view to the model.
- ng-model directive can be used with the (input, select, and textarea) html tags.
In the following example, we want to display the country properties using AngularJs Code:
- Country Flag: Path of the flag image.
- Country Name: Palestine
- Country Capital: Jerusalem
- Country Language: Arabic
1. Create the module, controller, and your data.
You can return to previous AngularJs posts to learn how to write AngularJs module and controller.
The example demonstrates a controller object with more than one property: (firstname, lastname, specialization, and gender)
- If you misspell a property name in the binding expression, angular expression will return null or undefined.
- If you misspelled the controller name, an error will be raised, and the binding expressions will not be evaluated.