AngularjsDatatable

Render Json data in Datatables with Angularjs

Render Json data in Datatables with Angularjs

Views

Hello to all, In this post, I will tell you, How to Render Json data in Datatables with Angularjs? Angularjs and jQuery Datatables both are very famous.

Here is working and tested code for Render Json data in Datatables with Angularjs:
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src= "https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.19/css/jquery.dataTables.min.css">
<script src= "http://ajax.googleapis.com/ajax/libs/angularjs/1.2.26/angular.min.js"></script>
</head>
<body ng-app="myApp">
<div  ng-controller="myCtrl">
    <table id="example" class="display" style="width:100%">
        <thead>
            <tr>
                <th>Name</th>
                <th>City</th>
                <th>Country</th>
            </tr>
        </thead>
        <tbody>
        </tbody>
    </table>
</div>
<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
     $scope.names = [
      { "Name" : "Max Joe", "City" : "Lulea", "Country" : "Sweden" },
      { "Name" : "Manish", "City" : "Delhi", "Country" : "India" },
      { "Name" : "Koniglich", "City" : "Barcelona", "Country" : "Spain" },
      { "Name" : "Wolski", "City" : "Arhus", "Country" : "Denmark" }
    ];
    console.log($scope.names);
    $('#example').DataTable({
       "ordering": true,
        "data": $scope.names,
        "searching": true,
        "columns": [
          {'data':'Name'},
          {'data':'City'},
          {'data':'Country'}
        ]
   });

});
</script>
</body>
</html>

 If you have any query related to this post, then please do comment below or ask questions.

Ajay Malhotra
the authorAjay Malhotra
Hello to all. Welcome to therichpost.com. Myself Ajay Malhotra and I am full stack developer. I love coding. I know Wordpress, Core php, Angularjs, Angular 2, Angular 6, Angular 7, laravel, Codeigniter, Shopify, Squarespace, Jquery, Google Map Api, Vuejs, Reactjs, Bigcommerce etc.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Positive SSL