</>
Skip to content
AngularJS lessons (25/28)

AngularJS — Tables

Basic Table

<table>
  <tr>
    <th>Name</th>
    <th>Email</th>
    <th>Age</th>
  </tr>
  <tr ng-repeat="user in users">
    <td>{{user.name}}</td>
    <td>{{user.email}}</td>
    <td>{{user.age}}</td>
  </tr>
</table>

Table with Filtering

<input ng-model="searchText" placeholder="Search...">

<table>
  <tr>
    <th>Name</th>
    <th>Email</th>
  </tr>
  <tr ng-repeat="user in users | filter:searchText">
    <td>{{user.name}}</td>
    <td>{{user.email}}</td>
  </tr>
</table>

Table with Ordering

<table>
  <tr>
    <th ng-click="orderBy('name')">Name</th>
    <th ng-click="orderBy('email')">Email</th>
  </tr>
  <tr ng-repeat="user in users | orderBy:sortColumn:reverseSort">
    <td>{{user.name}}</td>
    <td>{{user.email}}</td>
  </tr>
</table>

Controller

$scope.sortColumn = 'name';
$scope.reverseSort = false;

$scope.orderBy = function(column) {
  if ($scope.sortColumn === column) {
    $scope.reverseSort = !$scope.reverseSort;
  } else {
    $scope.sortColumn = column;
    $scope.reverseSort = false;
  }
};

Mini Practice

  1. Create a basic table
  2. Add search filtering
  3. Add sorting
  4. Combine filtering and sorting

Up Next

Continue with JSON — working with JSON.

Related Topics

Frequently Asked Questions about Tables

What is Tables in AngularJS?

Tables is a fundamental concept in AngularJS. This lesson explains it step by step with clear examples, making it easy for beginners to understand.

How do I learn Tables?

Start by reading the explanation above, then try the code examples. Practice by modifying the examples and experimenting with different values. Hands-on practice is the best way to learn Tables.

Why is Tables important in AngularJS?

Tables is essential for AngularJS development. Understanding this concept will help you write better code and solve real-world problems more effectively.