Creating an espacially ugly table, but a working one
This commit is contained in:
parent
c255e1ce1c
commit
45c752c869
4 changed files with 40 additions and 8 deletions
1
.~lock.world_data_v1.csv#
Normal file
1
.~lock.world_data_v1.csv#
Normal file
|
@ -0,0 +1 @@
|
|||
,hodasemi,michael.home,22.10.2018 10:19,file:///home/hodasemi/.config/libreoffice/4;
|
19
css/main.css
19
css/main.css
|
@ -26,6 +26,21 @@
|
|||
color: white;
|
||||
}
|
||||
|
||||
.table {
|
||||
|
||||
table#t01 {
|
||||
width: 100%;
|
||||
background-color: #f1f1c1;
|
||||
border-spacing: 5px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
table#t01 tr:nth-child(even) {
|
||||
background-color: #eee;
|
||||
}
|
||||
table#t01 tr:nth-child(odd) {
|
||||
background-color: #fff;
|
||||
}
|
||||
table#t01 th {
|
||||
color: white;
|
||||
background-color: black;
|
||||
padding: 15px;
|
||||
}
|
|
@ -24,7 +24,7 @@
|
|||
<!--
|
||||
<input type="file" id="csvFileInput" onchange="handleFiles(this.files)" accept=".csv" />
|
||||
-->
|
||||
<table id="table_bla"></table>
|
||||
<table id="t01"></table>
|
||||
|
||||
<script>
|
||||
handleFile()
|
||||
|
|
26
main.js
26
main.js
|
@ -20,18 +20,34 @@ function handleFile() {
|
|||
}
|
||||
|
||||
function processData(csv) {
|
||||
var table = "<table class='table'>";
|
||||
var table = "<table style='width:100%'>";
|
||||
|
||||
// split rows
|
||||
var allTextLines = csv.split(/\r\n|\n/);
|
||||
|
||||
for (var i = 0; i < allTextLines.length; i++) {
|
||||
var data = allTextLines[i].split(';');
|
||||
// create table header
|
||||
table += "<tr>";
|
||||
|
||||
var data = allTextLines[0].split(",");
|
||||
|
||||
for (var j = 0; j < data.length; j++) {
|
||||
table += "<th>";
|
||||
table += data[j];
|
||||
table += "</th>";
|
||||
}
|
||||
|
||||
table += "</tr>";
|
||||
|
||||
// create table content
|
||||
for (var i = 1; i < allTextLines.length; i++) {
|
||||
var data = allTextLines[i].split(',');
|
||||
|
||||
table += "<tr>";
|
||||
|
||||
for (var j = 0; j < data.length; j++) {
|
||||
table += "<td>";
|
||||
table += data[j];
|
||||
table += "</th>";
|
||||
table += "</td>";
|
||||
}
|
||||
|
||||
table += "</tr>";
|
||||
|
@ -39,5 +55,5 @@ function processData(csv) {
|
|||
|
||||
table += "</table>";
|
||||
|
||||
document.getElementById('table_bla').innerHTML = table;
|
||||
document.getElementById('t01').innerHTML = table;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue