Last active
November 18, 2020 12:22
-
-
Save namieluss/7980f7f7195bb8cf85f85a7712a1f15e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function htmlTableGenerator(content) { | |
let csv_preview = document.getElementById('csv-preview'); | |
let html = '<table id="example" class="table table-condensed table-hover table-striped" style="width:100%">'; | |
if (content.length == 0 || typeof(content[0]) === 'undefined') { | |
return null | |
} else { | |
const header = content[0]; | |
const data = content.slice(1); | |
html += '<thead>'; | |
html += '<tr>'; | |
header.forEach(function(colData) { | |
html += '<th>' + colData + '</th>'; | |
}); | |
html += '</tr>'; | |
html += '</thead>'; | |
html += '<tbody>'; | |
data.forEach(function(row) { | |
if (header.length === row.length) { | |
html += '<tr>'; | |
row.forEach(function(colData) { | |
html += '<td>' + colData + '</td>'; | |
}); | |
html += '</tr>'; | |
} | |
}); | |
html += '</tbody>'; | |
html += '</table>'; | |
// insert table element into csv preview | |
csv_preview.innerHTML = html; | |
// initialise DataTable | |
initDataTable(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment