Skip to content

Commit

Permalink
Except some headers
Browse files Browse the repository at this point in the history
  • Loading branch information
tksarah committed Mar 1, 2024
1 parent 8728643 commit 2288257
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -326,11 +326,44 @@ <h2> Data Table </h2>
});
}


function updateTableHeaders() {
const excludedHeaders = ['Address', 'dAppId']; // 除外するヘッダー
fetch('data.csv')
.then(response => response.text())
.then(content => {
const lines = content.split(/\r\n|\n/);
const headers = lines[0].split(',').filter(header => !excludedHeaders.includes(header.replace(/"/g, '')));
const table = document.getElementById('dataTable');
const tbody = table.querySelector('tbody');
tbody.innerHTML = '';
const thead = table.createTHead();
thead.innerHTML = '';
const row = thead.insertRow();
headers.forEach(header => {
const th = document.createElement('th');
th.textContent = header.replace(/"/g, '');
row.appendChild(th);
});
lines.slice(1).forEach(line => {
if(line.trim() === '') return;
const cells = line.split(',').filter((cell, index) => !excludedHeaders.includes(headers[index]));
const tr = tbody.insertRow();
cells.forEach(cellText => {
const td = tr.insertCell();
td.textContent = cellText.replace(/"/g, '');
});
});
}).catch(error => {
console.error(error);
});
}
</script>

<script>
// ページが読み込まれたときにloadCSVFile関数を呼び出します
window.onload = loadCSVFile;
// window.onload = loadCSVFile;
window.onload = updateTableHeaders;
</script>

</body>
Expand Down

0 comments on commit 2288257

Please sign in to comment.