JSFiddle - React, Tailwind, and code Playground
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
<script src="https://d3js.org/d3.v3.min.js"></script>
<link rel="stylesheet" href="../assets/css/scroll.css">
</head>
<body>
<div class="scrollable-table-wrapper">
<table id="TestTable">
<script>
d3.csv("componentlist.csv", function(error, data) {
if (error) throw error;
var columns = ["Status", "Component", "Last Run @"];
var table = d3.select("#TestTable").append("table"),
thead = table.append("thead"),
tbody = table.append("tbody");
// append the header row
thead.append("tr")
.selectAll("th")
.data(columns)
.enter()
.append("th")
.style("align", "center")
.text(function(column) { return column; });
var tr = tbody.selectAll("tr")
.data(data)
.enter().append("tr")
//Below statement is for setting alternate color code
.classed("even", function(d, i) { return i % 2 == 1; });
tr.each(function(d) {
console.log("inside tr.each");
var self = d3.select(this);
self.append("td")
.style("background-color", function(d) {
if(d.Status == "SUCCESS") {
return "green";
} else {
return "red";
}
});
self.append("td")
.append("a")
.attr("href", d.URL)
.text(d.Component)
self.append("td")
//<!--.style("text-align:center")-->
.html(d["Last"])
});
});
</script>
</table>
</div>
</body>
</html>
CSS
/*
componentlist.csv
Status,Component,URL,Last
SUCCESS,ABC,google.co.in,Thu Jul 19 08:15:43 UTC 2018
*/
/*scroll.css*/
body {
font-size: 16px;
}
table {
border-collapse: collapse;
max-width: 100%;
position: relative;
margin: 0;
border-spacing: 5px;
align: center;
}
thead {
position: relative;
top: 0;
left: 20;
width: 100%;
text-align: center;
}
tbody {
position: relative;
left: 20;
width: 100%;
}
table tbody tr:hover { background-color: #FFC; }
tfoot {
position: fixed;
bottom: 0;
left: 0;
}
thead th, tfoot th {
background: #ddd;
}
td, th {
border: 1px #ccc solid;
padding-left: 28px;
padding-right:18px;
padding-top: 2px;
padding-bottom: 2px;
text-align: left;
}