Categories

Tuesday, November 29, 2022
+919814419350 therichposts@gmail.com
AngularjsDatatable

Render Json data in Datatables with Angularjs

Render Json data in Datatables with Angularjs

4.37K

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.

therichpost
the authortherichpost
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 8, Angular 9, Angular 10, Angular 11, Angular12, Angular 13, Angular 14, Angular 15, Bootstrap 5, Nodejs, Laravel, Codeigniter, Shopify, Squarespace, jQuery, Google Map Api, Vuejs, Reactjs, Big commerce etc.

Leave a Reply

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