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 2288257 commit 44bf73c
Showing 1 changed file with 6 additions and 35 deletions.
41 changes: 6 additions & 35 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,12 @@ <h2> Data Table </h2>
}

function parseCSV(text) {

const excludedHeaders = ['Address', 'dAppId']; // 除外するヘッダー

const lines = text.split(/\r\n|\n/);
const headers = lines[0].split(',');
//const headers = lines[0].split(',');
const headers = lines[0].split(',').filter(header => !excludedHeaders.includes(header.replace(/"/g, '')));
headers.push('Current Tier'); // 'Current Tier' ヘッダーを追加
headers.push('Amount/Staker'); // 'Amount/Staker' ヘッダーを追加
const table = document.getElementById('dataTable');
Expand Down Expand Up @@ -326,44 +330,11 @@ <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 = updateTableHeaders;
window.onload = loadCSVFile;
</script>

</body>
Expand Down

0 comments on commit 44bf73c

Please sign in to comment.