JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js"></script>
<div id="table"></div>
<p> </p>Script prints out the following:
<pre class="prettyprint">
<code class="prettyprint">
<div id="table">
<table>
<tr>
<td colspan="3"><p>Table</p></td>
</tr>
<tr>
<td><p>Attempt #1</p></td>
<td><p>John Doe</p></td>
<td><p>508-555-1234</p></td>
</tr>
<tr>
<td><p>Attempt #2</p></td>
<td><p>Jane Doe</p></td>
<td><p>775-555-5678</p></td>
</tr>
<tr>
<td><p>Attempt #3</p></td>
<td><p>Adam Doe</p></td>
<td><p>603-555-9012</p></td>
</tr>
<tr>
<td><p>Attempt #4</p></td>
<td><p>Karen Doe</p></td>
<td><p>978-555-3456</p></td>
</tr>
<tr>
<td><p>Attempt #5</p></td>
<td><p>Trish Doe</p></td>
<td><p>603-555-7890</p></td>
</tr>
<tr>
<td><p>Attempt #6</p></td>
<td><p>Company</p></td>
<td><p>(try to reach someone)</p></td>
</tr>
</table>
</div>
</code>
</pre>
CSS
/* --------------------------
* Global Styles
* --------------------------
*/
body {
font-family:sans-serif;
}
/* --------------------------
* Table Styles
* --------------------------
*/
table {
margin: 0px;
border-collapse: collapse;
display: inline;
table-layout:fixed;
}
table tr:first-child td, table tr:first-child td p {
background-color: #00549f;
color: #ffffff;
font-weight: 700;
}
table tr:first-child td:first-child {
border-top-left-radius: 8px;
}
table tr:first-child td:last-child {
border-top-right-radius: 8px;
}
table tr:last-child td:first-child {
border-bottom-left-radius: 8px;
}
table tr:last-child td:last-child {
border-bottom-right-radius: 8px;
}
table td {
text-align: center;
border: 2px solid #00549f;
min-width: 300px;
}
table td p {
margin: 0;
padding: 0;
}
table tr:nth-child(even) {
background: #ECF0F1;
}
table tr:hover {
background: #BDC3C7;
color: #ffffff !important;
}
table a {
color: inherit;
text-decoration: none;
}
table a:hover {
color: inherit;
}
JavaScript
//<![CDATA[
//employee array
window.onload = function () {
function getSorted(arr, sortArr) {
var result = [];
for(var i=0; i<sortArr.length; i++) {
result[i] = arr[sortArr[i]];
}
return result;
}
var array = [],
sortArr = [0,6,4,7,9,1],
sortedArr;
array[0] = {name: "John Doe",number: "508-555-1234"};
array[1] = {name: "Jane Doe",number: "775-555-5678"};
array[2] = {name: "Adam Doe",number: "603-555-9012"};
array[3] = {name: "Karen Doe",number: "978-555-3456"};
array[4] = {name: "Trish Doe",number: "603-555-7890"};
array[5] = {name: "Company",number: "(try to reach someone)"};
array[6] = {name: "Tom Doe",number: "101-555-7890"};
array[7] = {name: "Kim Doe",number: "102-555-7890"};
array[8] = {name: "Logan Doe",number: "103-555-7890"};
array[9] = {name: "Bill Doe",number: "104-555-7890"};
array[10] = {name: "Bob Doe",number: "105-555-7890"};
sortedArr = getSorted(array, sortArr);
var theTable = document.createElement("table");
currentIndex = 0;
lastIndex = array.length - 1;
//write table header
while (true) {
tr = document.createElement("tr");
td0 = document.createElement("td");
td0.colSpan = 3;
p = document.createElement("p");
p.appendChild(document.createTextNode("Table"));
td0.appendChild(p);
tr.appendChild(td0);
theTable.appendChild(tr);
break;
}
//for each employee in above array, write the attemp#, their name, and their contact info
for (var i = 0, tr, td; i < sortArr.length; i++) {
...