TablesTutorials

how to create a Angular Table Row

how to create a Angular Table Row

how to create a Angular Table Row

Before We Start

Every developers need, clean and modern elements to develop their websites, It contain pictures and a user interface element within a website. The most important one and the first section that the user sees when he/she enters a website. how to create a Angular Table Row

So if you are a person who wishes to develop a website, you have to know how to create that properly.

how to create a Angular Table Row

Download Udemy paid courses FREE

We are here to solve your problem. In this article we discuss how to create this elements. Before we start please read the below articles which easier you to understand the process, if you are new to development.

Step 1 – Add HTML

It’s too easy and simple. Just copy and paste below code in your HTML editor between <body> </body> tag.

<body ng-app='myApp' ng-controller='myCtrl' class="container">
  <h1>Angular Table Rows</h1>
  <table class="table-striped table-bordered">
    <thead>
      <tr>
        <th ng-repeat="column in tblData">{{ column }}</th>
        <th></th>
      </tr>
    </thead>
    <tbody>
      <tr id="row{{rowId}}" ng-repeat="row in tblData" ng-init="rowId = $index">
        <td ng-repeat="cell in tblData">{{ rowId }}{{cell}} </td>
        <td><button class="btn btn-primary" ng-click="remove(rowId)">Remove</button></td>
      </tr>
    </tbody>
  </table>
  <h2>Objectives</h2>
  <ol>
    <li>Clicked button executes a function, disables, and shows activity spinner within the clicked button</li>
    <li>onFail: button reactivates and turns red</li>
    <li>onSuccess: associated row is replaced with status message "Sent {rowId} Successfully"</li>
    <li>Each button can be clicked to start it's own process</li>
  </ol>
</body>

Step 2 – Add CSS

Download Udemy paid courses FREE

We use some external CSS link to this code. No need to worry about this, copy and paste below code between <style></style> tag.

<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css">
</head>

Copy and paste below code in your HTML editor between <style></style> tag.

<style>
table {
  max-width: 100%;
  min-width: 50%;
}
td,
th {
  min-width: 100px;
  height: 50px;
  text-align: center;
  color: #ddd;
}
h2,
ol {
  color: #999;
}
.alert-success td {
  color: #3c763d;
}

.alert td button {
  margin-right: 30px;
}

</style>

Step 3 – Add JavaScript

We use some external JavaScript link to this code. No need to worry about this, copy and paste below code between <head></head> tag.

<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.2/angular.min.js"></script>
<script src="https://code.jquery.com/jquery-1.11.1.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/spin.js/2.0.1/spin.min.js"></script>
</head>

And also copy and paste below JavaScript code between <script></script> tag.

<script>
angular
  .module("myApp", [])

  .controller("myCtrl", function ($scope) {
    $scope.tblData = getData();

    $scope.remove = function (rowId) {
      var target = "#row" + rowId;
      $(target).replaceWith(getTemplate(rowId));
      console.log("removing " + target);
    };

    function getData() {
      return ["A", "B", "C", "D", "E"];
    }

    function getTemplate(id) {
      var t = "";
      t += '<tr class="alert alert-success alert-dismissible">';
      t += '<td colspan="6">';
      t +=
        '<button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>';
      t +=
        "<strong>Done!</strong> Removed RowId[" +
        id +
        "] Successfully</td></tr>";

      return t;
    }
  });

</script>

At the end we will have something like this. You can change fonts, colors, backgrounds and all things that you want.Enjoy it.

how to create a Angular Table Row

Video Tutorial

Please watch this video to better understand this tutorial and don’t forget to subscribe to our channel.

Download Udemy paid courses FREE


Help others to find out about this article on Social Media sites. If you have any doubt or any problem, don’t hesitate to contact us. Thereafter we will be able to help you and also make sure you bookmark our site on your browser.

Related Articles

Leave a Reply

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

Back to top button