
how to create a Angular Material Table
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 Material Table
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 Material Table
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.
<html lang="en" ng-app="StarterApp">
<body layout="column" ng-controller="AppCtrl">
<div class="main-fab">
<md-button class="md-fab md-accent">+</md-button>
</div>
<md-toolbar class="md-tall" layout="column"><span flex="flex"></span>
<div class="md-toolbar-tools">
<div class="fill-height" layout="row" flex="flex">
<div class="md-toolbar-item md-breadcrumb" ng-hide="toggleSearch"><span ng-click="toggleSearch = !toggleSearch">Angular Material Table</span></div><span flex="flex" ng-hide="toggleSearch"></span>
<md-input-container flex="flex" style="padding-left:88px;" ng-show="toggleSearch">
<input id="searchinput" type="text" ng-model="search" show-focus="toggleSearch"/>
</md-input-container>
<div class="md-toolbar-item md-tools" layout="row"><a class="md-button md-default-theme" href="#" ng-click="toggleSearch = !toggleSearch"><i class="ion-android-search"></i></a></div>
</div>
</div>
</md-toolbar>
<md-content layout="column" flex="flex" ng-click="toggleSearch=false">
<md-table headers="headers" content="content" sortable="sortable" filters="search" custom-class="custom" thumbs="thumbs" count="count"></md-table>
</md-content>
</body>
</html>
<!-- md-table jade template-->
<div id="md-table-template" ng-hide="true">
<table class="md-table" md-colresize="md-colresize">
<thead>
<tr class="md-table-headers-row">
<th class="md-table-header" ng-repeat="h in headers"><a href="#" ng-if="handleSort(h.field)" ng-click="reverse=!reverse;order(h.field,reverse)">{{h.name}} <i class="ion-android-arrow-dropup" ng-show="reverse && h.field == predicate"></i><i class="ion-android-arrow-dropdown" ng-show="!reverse && h.field == predicate"></i></a><span ng-if="!handleSort(h.field)">{{h.name}}</span></th>
<th class="md-table-header"></th>
</tr>
</thead>
<tbody>
<tr class="md-table-content-row" ng-repeat="c in content | filter:filters | startFrom:tablePage*count | limitTo: count">
<td>
<div class="md-table-thumbs" ng-repeat="h in headers" ng-if="h.field == thumbs">
<div style="background-image:url({{c.thumb}})"></div>
</div>
</td>
<td class="md-table-content" ng-repeat="h in headers" ng-class="customClass[h.field]" ng-if="h.field != thumbs">{{(h.field.indexOf('date') > 0) ? $filter('date')(c[h.field]) : c[h.field];}}</td>
<td class="md-table-td-more">
<md-button aria-label="Info"><i class="ion-android-more-vertical"></i></md-button>
</td>
</tr>
</tbody>
</table>
<div class="md-table-footer" layout="row"><span class="md-table-count-info">Rows per page : <a href="#" ng-click="goToPage(0); count=10">10</a>,<a href="#" ng-click="goToPage(0); count=25">25</a>,<a href="#" ng-click="goToPage(0); count=50">50</a>,<a href="#" ng-click="goToPage(0); count=100">100</a>(current is {{count}})</span><span flex="flex"></span><span ng-show="nbOfPages() > 1">
<md-button class="md-primary md-hue-2" ng-disabled="tablePage==0" ng-click="tablePage=tablePage-1" aria-label="Previous Page"><i class="ion-chevron-left" style="font-size:16px;"></i></md-button><a href="#" ng-repeat="i in getNumber(nbOfPages()) track by $index">
<md-button class="md-primary md-hue-2 md-table-footer-item" ng-click="goToPage($index)"><span ng-class="{ 'md-table-active-page': tablePage==$index}">{{$index+1}}</span></md-button></a>
<md-button class="md-primary md-hue-2" ng-disabled="tablePage==nbOfPages()-1" ng-click="tablePage=tablePage+1" aria-label="Next Page"><i class="ion-chevron-right" style="font-size:16px;"></i></md-button></span></div>
</div>
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://ajax.googleapis.com/ajax/libs/angular_material/0.7.1/angular-material.min.css">
<link rel="stylesheet" href="https://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css">
</head>
Copy and paste below code in your HTML editor between <style></style> tag.
<style>
a {
text-decoration: none;
}
i {
vertical-align: middle;
font-size: 24px;
}
.main-fab {
position: absolute;
z-index: 20;
font-size: 30px;
top: 100px;
left: 24px;
transform: scale(0.88, 0.88);
}
.md-breadcrumb {
padding-left: 88px;
}
.JCLRgrip:first-child {
left: 105px !important;
display: none !important;
}
.JColResizer th:first-child {
width: 105px !important;
}
.md-table {
min-width: 100%;
border-collapse: collapse;
}
.md-table tbody tr:hover,
.md-table tbody tr:focus {
cursor: pointer;
background-color: rgba(63, 81, 181, 0.2);
}
.md-table-header {
border-bottom: 1px solid rgb(230, 230, 230);
color: rgb(130, 130, 130);
text-align: left;
font-size: 0.75em;
font-weight: 700;
padding: 16px 16px 16px 0;
}
.md-table-header a {
text-decoration: none;
color: inherit;
}
.md-table-content {
white-space: nowrap;
font-size: 0.8em;
padding: 16px 16px 16px 0;
height: 72px;
}
.md-table-td-more {
max-width: 72px;
width: 72px;
padding: 16px;
}
.md-table-thumbs {
max-width: 104px;
width: 104px;
padding: 16px 32px;
}
.md-table-thumbs div {
overflow: hidden;
width: 40px;
height: 40px;
border-radius: 20px;
border: 1px solid rgba(0, 0, 0, 0.2);
background-size: cover;
box-shadow: 0 8px 10px rgba(0, 0, 0, 0.3);
-webkit-box-shadow: 0 8px 10px rgba(0, 0, 0, 0.1);
}
.md-table-footer {
height: 40px;
padding-left: 32px;
padding-right: 32px;
}
.md-table-count-info {
line-height: 40px;
font-size: 0.75em;
}
.md-table-footer-item {
width: 40px;
height: 40px;
vertical-align: middle;
}
.md-table-active-page {
font-weight: 700;
}
.bold {
font-weight: 700;
}
.grey {
color: grey;
}
md-input-container.md-default-theme .md-input {
color: white;
border-color: white;
margin-top: 24px;
}
</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/jquery/1.11.2/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.10/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.6/angular-animate.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.6/angular-aria.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angular_material/0.7.1/angular-material.min.js"></script>
<script src="https://greggman.com/downloads/examples/colresizable/colResizable-1.5.min.js"></script>
</head>
And also copy and paste below JavaScript code between <script></script> tag.
<script>
var app = angular.module("StarterApp", ["ngMaterial"]);
app.controller("AppCtrl", [
"$scope",
function ($scope) {
$scope.toggleSearch = false;
$scope.headers = [
{
name: "",
field: "thumb"
},
{
name: "Name",
field: "name"
},
{
name: "Description",
field: "description"
},
{
name: "Last Modified",
field: "last_modified"
}
];
$scope.content = [
{
thumb:
"https://lh3.googleusercontent.com/-5NfcdlvGQhs/AAAAAAAAAAI/AAAAAAAAABY/ibGrApGYTuQ/photo.jpg",
name: "Bruno Mars",
description: "Human",
last_modified: "Jun 5, 2014"
},
{
thumb:
"http://www.otakia.com/wp-content/uploads/V_1/article_3573/7405.jpg",
name: "AT-AT",
description: "Robot",
last_modified: "Jun 5, 2014"
},
{
thumb:
"https://speakerdata.s3.amazonaws.com/photo/image/774492/Mark-Ronson-r24.jpg",
name: "Mark Ronson",
description: "Human",
last_modified: "Jun 5, 2014"
},
{
thumb:
"https://25.media.tumblr.com/61ebf04c3cc7a84944aa0246e902f2a7/tumblr_mm35b87dGz1qmwrnuo1_1280.jpg",
name: "Daft Punk",
description: "Human-Robot",
last_modified: "Jun 5, 2014"
},
{
thumb:
"http://thatgrapejuice.net/wp-content/uploads/2014/03/lady-gaga-that-grape-juice-televisionjpg.jpg",
name: "Lady Gaga",
description: "Undefined",
last_modified: "Jun 5, 2014"
}
];
$scope.custom = {
name: "bold",
description: "grey",
last_modified: "grey"
};
$scope.sortable = ["name", "description", "last_modified"];
$scope.thumbs = "thumb";
$scope.count = 3;
}
]);
app.directive("mdTable", function () {
return {
restrict: "E",
scope: {
headers: "=",
content: "=",
sortable: "=",
filters: "=",
customClass: "=customClass",
thumbs: "=",
count: "="
},
controller: function ($scope, $filter, $window) {
var orderBy = $filter("orderBy");
$scope.tablePage = 0;
($scope.nbOfPages = function () {
return Math.ceil($scope.content.length / $scope.count);
}),
($scope.handleSort = function (field) {
if ($scope.sortable.indexOf(field) > -1) {
return true;
} else {
return false;
}
});
$scope.order = function (predicate, reverse) {
$scope.content = orderBy($scope.content, predicate, reverse);
$scope.predicate = predicate;
};
$scope.order($scope.sortable[0], false);
$scope.getNumber = function (num) {
return new Array(num);
};
$scope.goToPage = function (page) {
$scope.tablePage = page;
};
},
template: angular
.element(document.querySelector("#md-table-template"))
.html()
};
});
//UNCOMMENT BELOW TO BE ABLE TO RESIZE COLUMNS OF THE TABLE
/*
app.directive('mdColresize', function ($timeout) {
return {
restrict: 'A',
link: function (scope, element, attrs) {
scope.$evalAsync(function () {
$timeout(function(){ $(element).colResizable({
liveDrag: true,
fixed: true
});},100);
});
}
}
});
*/
app.directive("showFocus", function ($timeout) {
return function (scope, element, attrs) {
scope.$watch(
attrs.showFocus,
function (newValue) {
$timeout(function () {
newValue && element.focus();
});
},
true
);
};
});
app.filter("startFrom", function () {
return function (input, start) {
start = +start;
return input.slice(start);
};
});
</script>
At the end we will have something like this. You can change fonts, colors, backgrounds and all things that you want.Enjoy it.

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.