{"id":80,"date":"2018-04-30T22:06:00","date_gmt":"2018-04-30T22:06:00","guid":{"rendered":"https:\/\/kindsonthegenius.com\/blog\/2018\/04\/30\/how-to-add-a-progressbar-column-to-table-using-angularjs-and-bootstrap-ui\/"},"modified":"2020-11-05T14:20:39","modified_gmt":"2020-11-05T13:20:39","slug":"how-to-add-a-progressbar-column-to-table-using-angularjs-and-bootstrap-ui","status":"publish","type":"post","link":"https:\/\/kindsonthegenius.com\/blog\/how-to-add-a-progressbar-column-to-table-using-angularjs-and-bootstrap-ui\/","title":{"rendered":"How to Add a Progressbar Column to Table Using AngularJS and BootStrap UI"},"content":{"rendered":"<p>In this tutorial, we are going to learn how to add a progress bar column to HTML table using AngularJS<\/p>\n<div style=\"clear: both; text-align: center;\"><\/div>\n<p><b>Content<\/b><\/p>\n<ol>\n<li><a href=\"https:\/\/kindsonthegenius.com\/blog\/how-to-add-a-progressbar-column-to-table-using-angularjs-and-bootstrap-ui#t1\">Introduction <\/a><\/li>\n<li><a href=\"https:\/\/kindsonthegenius.com\/blog\/how-to-add-a-progressbar-column-to-table-using-angularjs-and-bootstrap-ui#t2\">About AngularJS <\/a><\/li>\n<li><a href=\"https:\/\/kindsonthegenius.com\/blog\/how-to-add-a-progressbar-column-to-table-using-angularjs-and-bootstrap-ui#t3\">What you Need <\/a><\/li>\n<li><a href=\"https:\/\/kindsonthegenius.com\/blog\/how-to-add-a-progressbar-column-to-table-using-angularjs-and-bootstrap-ui#t4\">How it works<\/a><\/li>\n<li><a href=\"https:\/\/kindsonthegenius.com\/blog\/how-to-add-a-progressbar-column-to-table-using-angularjs-and-bootstrap-ui#t5\">How to Vary Color Based on Value <\/a><\/li>\n<li><a href=\"#t6\">Final Notes<\/a><\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<h3 id=\"t1\">1. Introduction<\/h3>\n<p>By now you should know how to display tabular data using AnuglarJS. If not you can look at this lesson: <a href=\"https:\/\/kindsonthegenius.com\/blog\/how-to-fetch-sharepoint-list-using-angularjs-and-display-on-html-page-explaining-the-codes\/\" target=\"_blank\" rel=\"noopener noreferrer\">Display SharePoint Table Using AngularJS <\/a><br \/>\nRemember you can reach me if you have challenges.<\/p>\n<p>Sometime you may need to display percentages in a progress bar in a table column. Or it may be number of points a user have accumulated in membership website. Using a progress-bar would make it more interesting for your users.<\/p>\n<p>&nbsp;<\/p>\n<h3 id=\"t2\">2. About AngularJS<\/h3>\n<p>AngularJS is a very easy to use framework that helps you to create dynamic page that integrates data into your html page using AngularJS markup.<br \/>\nAll you need to to is to add the link to the js file in the head tag of your page.<\/p>\n<p>&nbsp;<\/p>\n<h3 id=\"t3\">\n3. What You Need<\/h3>\n<ul>\n<li>BootStrap<\/li>\n<li>JQuery<\/li>\n<li>AngularJS<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<h3 id=\"t4\">4. How it Works<\/h3>\n<p>It works in a very simple way.<br \/>\nThe lenght of the progress bar is defined by the values in another column of the table. So basically, any table that have a column containing number can be used to display a progressbar.<\/p>\n<p>The code is shown in Listing 1.0.<\/p>\n<p><!-- HTML generated using hilite.me --><\/p>\n<pre style=\"line-height: 125%; margin: 0;\"><span style=\"color: #062873; font-weight: bold;\">&lt;table<\/span> <span style=\"color: #4070a0;\">border=\"1\"<\/span> <span style=\"color: #4070a0;\">class=\"em-c-table\"<\/span><span style=\"color: #062873; font-weight: bold;\">&gt;<\/span>\r\n    <span style=\"color: #062873; font-weight: bold;\">&lt;thead<\/span> <span style=\"color: #4070a0;\">class=\"em-c-table__header\"<\/span><span style=\"color: #062873; font-weight: bold;\">&gt;<\/span>\r\n        <span style=\"color: #062873; font-weight: bold;\">&lt;tr<\/span> <span style=\"color: #062873; font-weight: bold;\">&gt;<\/span>\r\n            <span style=\"color: #062873; font-weight: bold;\">&lt;th&gt;<\/span>Name<span style=\"color: #062873; font-weight: bold;\">&lt;\/th&gt;<\/span>\r\n            <span style=\"color: #062873; font-weight: bold;\">&lt;th&gt;<\/span>Points<span style=\"color: #062873; font-weight: bold;\">&lt;\/th&gt;<\/span>\r\n            <span style=\"color: #062873; font-weight: bold;\">&lt;td&gt;<\/span>Percentage<span style=\"color: #062873; font-weight: bold;\">&lt;\/td&gt;<\/span>\r\n        <span style=\"color: #062873; font-weight: bold;\">&lt;\/tr&gt;<\/span>\r\n    <span style=\"color: #062873; font-weight: bold;\">&lt;\/thead&gt;<\/span>\r\n    <span style=\"color: #062873; font-weight: bold;\">&lt;tbody<\/span> <span style=\"color: #4070a0;\">class=\"em-c-table__body\"<\/span><span style=\"color: #062873; font-weight: bold;\">&gt;<\/span>\r\n        <span style=\"color: #062873; font-weight: bold;\">&lt;tr<\/span> <span style=\"color: #4070a0;\">ng-repeat=\"row in data\"<\/span><span style=\"color: #062873; font-weight: bold;\">&gt;<\/span>\r\n            <span style=\"color: #062873; font-weight: bold;\">&lt;td&gt;<\/span>{{row.Name}}<span style=\"color: #062873; font-weight: bold;\">&lt;\/td&gt;<\/span>\r\n            <span style=\"color: #062873; font-weight: bold;\">&lt;td&gt;<\/span>{{row.Points}}<span style=\"color: #062873; font-weight: bold;\">&lt;\/td&gt;<\/span>\r\n            <span style=\"color: #062873; font-weight: bold;\">&lt;td&gt;&lt;div<\/span> <span style=\"color: #4070a0;\">class=\"progress progress-striped\"<\/span><span style=\"color: #062873; font-weight: bold;\">&gt;<\/span>\r\n <span style=\"color: #062873; font-weight: bold;\">     &lt;div<\/span> <span style=\"color: #4070a0;\">class=\"progress progress-bar-warning\"<\/span> <span style=\"color: #4070a0;\">ng-style=\"{width: row.Percentage+'%'}\"<\/span><span style=\"color: #062873; font-weight: bold;\">&gt;<\/span> {{row.Percentage}}<span style=\"color: #062873; font-weight: bold;\">&lt;\/div&gt;<\/span>\r\n      <span style=\"color: #062873; font-weight: bold;\">&lt;\/div&gt;&lt;\/td&gt;<\/span>\r\n        <span style=\"color: #062873; font-weight: bold;\">&lt;\/tr&gt;<\/span>\r\n     <span style=\"color: #062873; font-weight: bold;\">&lt;\/tbody&gt;<\/span>\r\n <span style=\"color: #062873; font-weight: bold;\">&lt;\/table&gt;<\/span><\/pre>\n<p><b>Listing 1.0: <\/b>HTML Table Structure<\/p>\n<p>&nbsp;<\/p>\n<p>The progressbar is displayed in the third column of the table<br \/>\nNote there are two div tags and one ng-style attribute<\/p>\n<ul>\n<li>The first div tag sets the type of progressbar:\u00a0 &#8220;progress progress-stripped<\/li>\n<li>The second div tag sets the\u00a0 color: &#8220;progress progress-bar-warning&#8221;<\/li>\n<li>The ng-style is used to set the width of the bar to the value of the Percentage field in the table.<\/li>\n<\/ul>\n<p>I hope this is clear. But if not, leave me a comment. I would explain more clearly to you.<\/p>\n<p>&nbsp;<\/p>\n<h3 id=\"ht\">5. How to Change Color Based on Value<\/h3>\n<p>You may want to vary the color of the bar depending on the value of the lenght. For example:<br \/>\n0 &#8211; 60: green<br \/>\n61 &#8211; 90: orange<br \/>\n91 &#8211; 99: red<\/p>\n<p>To achieve this, you simply need to add a simple class to the &lt;td&gt; tag.<\/p>\n<p><!-- HTML generated using hilite.me --><\/p>\n<pre style=\"margin: 0; line-height: 125%;\">ng-class=\"{'progress-bar-danger': percent<span style=\"color: #007700;\">&lt;33<\/span><span style=\"color: #ff0000; background-color: #ffaaaa;\">,<\/span> <span style=\"color: #ff0000; background-color: #ffaaaa;\">'<\/span><span style=\"color: #0000cc;\">progress-bar-info<\/span><span style=\"color: #ff0000; background-color: #ffaaaa;\">'<\/span><span style=\"color: #0000cc;\">:<\/span> <span style=\"color: #0000cc;\">percent<\/span><span style=\"color: #007700;\">&gt;<\/span>=33 <span style=\"color: #ff0000; background-color: #ffaaaa;\">&amp;&amp;<\/span> percent<span style=\"color: #007700;\">&lt;66<\/span><span style=\"color: #ff0000; background-color: #ffaaaa;\">,<\/span> <span style=\"color: #ff0000; background-color: #ffaaaa;\">'<\/span><span style=\"color: #0000cc;\">progress-bar-success<\/span><span style=\"color: #ff0000; background-color: #ffaaaa;\">'<\/span><span style=\"color: #0000cc;\">:<\/span> <span style=\"color: #0000cc;\">percent<\/span><span style=\"color: #007700;\">&gt;<\/span>=66}\"<\/pre>\n<p>&nbsp;<\/p>\n<h3 id=\"t6\">6. Final Notes<\/h3>\n<p>Make sure you try it yourself. Just copy the code to your IDE and try to modify it to fit your data and then make sure it works.<br \/>\nIf you completed this tutorial, thumbs up to you!. If you have any challenges, let me know in the comment box below or to the left of this page.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial, we are going to learn how to add a progress bar column to HTML table using AngularJS Content Introduction About AngularJS What &hellip; <\/p>\n","protected":false},"author":2,"featured_media":634,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0},"categories":[113],"tags":[],"_links":{"self":[{"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/posts\/80"}],"collection":[{"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/comments?post=80"}],"version-history":[{"count":9,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/posts\/80\/revisions"}],"predecessor-version":[{"id":1768,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/posts\/80\/revisions\/1768"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/media\/634"}],"wp:attachment":[{"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/media?parent=80"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/categories?post=80"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kindsonthegenius.com\/blog\/wp-json\/wp\/v2\/tags?post=80"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}