angular

Angular Datatable Pagination, Sorting and Searching Using Ajax

Angular Datatable is an angular module for provides a datatable directive along with datatable options helpers. Angular Datatable module helps to create beautiful grid listing in your angular application using angular directive.

There are many angular directives and modules available for table grid but datatable is the most popular table grid plugin.

The main benefit of Angular Data-table is open source and light weighted. You can use this plugin with other css frameworks like bootstrap and foundation. You can learn more from the official website angular-datatables.

I got a huge response from readers on the previous datatable tutorial which was DataTables Example – Server-side Processing with PHP, Here I am letting you know how to integrate datatable angular module with your application.

You can also check other tutorials of angular,

We are using the below Files:

Index.html - This file will responsible to create an HTML table, angular module and instance datatable using angular code.
Library files - I have used jquery,angular-datatable and bootstrap lib files.

Simple Example of Angular Datatable Module

Step 1: We will include jquery data-table and jquery library in (index.html).

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"></script>
<script src="angular-datatables.min.js"></script>
<script src="jquery.dataTables.min.js"></script>

Here, I have included all necessary library files which are useful to integrate angular datatable with application.

Related Post

Step 2: Create an Angular app for listing in (index.html).

angular.module('TestApp', ['TestApp.controllers','datatables']);

Here I have injected datatables module within our angular app.

Step 3: Now created sample JSON data and injected datatable options into the listing controller in (index.html).

angular.module('TestApp.controllers', []).controller('testController', function($scope,DTOptionsBuilder, DTColumnBuilder) {
    $scope.userList = [
        {
          
          Name: 'Parvez Alam',
          Age: '28'
        },
        
       {
        Name: 'Sameer',
        Age: '13'
        },
        {
        Name: 'Rakesh',
        Age: '55'
        },
        {
        Name: 'Ramesh',
        Age: '44'
        },
        {
        Name: 'Aman',
        Age: '34'
        },
        {
        Name: 'John',
        Age: '23'
        }
      ];

These datatable parameters DTOptionsBuilder, DTColumnBuilder help to control datatable listing table, You can set a number of columns, map column to value, sort column and order of column etc.

Step 4: Configured datatable option and column order using the below code in (index.html).

$scope.vm = {};
$scope.vm.dtOptions = DTOptionsBuilder.newOptions().withOption('order', [0, 'asc']);

Step 5: Created HTML table and iterate records using foreach loop in (index.html).

<table class="table table-striped table-bordered" datatable="ng">
 <thead>
  <tr>
   <th>Sr</th>
   <th>Name</th>
   <th>Age</th>
   <th>Action</th>
  </tr>
 </thead>
 <tbody>
  <tr ng-repeat="user in userList">
   <td>{{$index + 1}}</td>
   <td>{{user.Name}}</td>
   <td>{{user.Age}}</td>
   <td>
    <div class="btn-group">
       <button type="button" class="btn btn-default btn" ng-click="edit($index);"><i class="glyphicon glyphicon-pencil"></i></button>  
       <button type="button" class="btn btn-default btn" ng-click="delete();"><i class="glyphicon glyphicon-trash"></i></button> 
    </div>
   </td>
  </tr>
 </tbody>
</table>

Conclusion

We have learned about the simple integration of angular datatable into an angular application. We have converted HTML table into an wonderful grid using datatable directive without any any complex coding.

You can download the source code and Demo from the below link.

View Comments

Recent Posts

Configure and Retrieve S3 Information Using Laravel PHP-AWS-SDK

This tutorial helps integrate a PHP SDK with Laravel. We'll install aws-php-sdk into laravel application and access all aws services… Read More

2 months ago

What is the Purpose of php_eol in PHP?

in this quick PHP tutorial, We'll discuss php_eol with examples. PHP_EOL is a predefined constant in PHP and represents an… Read More

8 months ago

Laravel Table Relationship Methods With Example

This Laravel tutorial helps to understand table Relationships using Elequonte ORM. We'll explore laravel table Relationships usage and best practices… Read More

8 months ago

Exploring the Power of Laravel Eloquent Join?

We'll explore different join methods of Laravel eloquent with examples. The join helps to fetch the data from multiple database… Read More

9 months ago

Quick and Easy Installation of Laravel Valet

in this Laravel tutorial, We'll explore valet, which is a development environment for macOS minimalists. It's a lightweight Laravel development… Read More

9 months ago

What is Laravel Soft Delete and How Does it Work?

I'll go through how to use soft delete in Laravel 10 in this post. The soft deletes are a method… Read More

9 months ago

Categories