datatables-in-angularmaterial

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.

By therichpost

Hello to all. Welcome to therichpost.com. Myself Ajay Malhotra and I am freelance full stack developer. I love coding. I know WordPress, Core php, Angularjs, Angular 19, MedusaJs, Next.js, Bootstrap 5, Nodejs, Laravel, Codeigniter, Shopify, Squarespace, jQuery, Google Map Api, Vuejs, Reactjs, Big commerce etc.

Leave a Reply

Your email address will not be published. Required fields are marked *

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