I wrote a code to load data, adding and removing appended columns. However I am not able to remove the last header (of appended column). I managed to figure out to remove the first column header. Please see testing function. Is there a way to remove one cell header or removing a column with a header? The command
tbl.removeChild(tbl.firstChild);
removes only the first header of the first column. However, the code
tbl.removeChild(tbl.lastChild);
removes all data instead last header of the last appended column. What I am missing here?
Update: I managed to remove the last header but only once, next last column is removed but the header stay. Still, I am not able to solve the glitch. The code I modified is marked
Below is the complete code,
var flag1 = false;
var file = document.getElementById('inputfile');
var txtArr = [];
if (typeof(document.getElementsByTagName("table")[0]) != "undefined") {
document.getElementsByTagName("table")[0].remove();
}
// get the reference for the body
var body = document.getElementsByTagName("body")[0];
// creates a <table> element and a <tbody> element
var tbl = document.createElement("table"),
thead = document.createElement('thead');
var tblBody = document.createElement("tbody");
file.addEventListener('change', () => {
var fr = new FileReader();
fr.onload = function() {
// By lines
var lines = this.result.split('\n');
for (var line = 0; line < lines.length; line++) {
txtArr.push(lines[line].split(" "));
}
}
fr.readAsText(file.files[0]);
});
//console.log(flag1);
// document.getElementById('output').textContent=txtArr.join("");
//document.getElementById("output").innerHTML = txtArr[0];
// console.log(txtArr[2]);
function generate_table() {
// creating all cells
if (flag1 == false) {
th = document.createElement('th'),
th.innerHTML = "Name";
tbl.appendChild(th);
th = document.createElement('th');
th.innerHTML = "Sample1";
tbl.appendChild(th);
tbl.appendChild(thead);
tbl.appendChild(tblBody);
} //endif flag1=false
else {
th = document.createElement('th');
th.innerHTML = "Sample2";
tbl.appendChild(th);
tbl.appendChild(thead);
tbl.appendChild(tblBody);
}
for (var i = 0; i < txtArr.length - 1; i++) {
// creates a table row
var row = document.createElement("tr");
for (var j = 0; j < 2; j++) {
var cell = document.createElement("td");
var cellText = document.createTextNode(txtArr[i][j]);
cell.appendChild(cellText);
row.appendChild(cell);
tblBody.appendChild(row);
}
flag1 = true;
// put the <tbody> in the <table>
tbl.appendChild(tblBody);
// appends <table> into <body>
body.appendChild(tbl);
// sets the border attribute of tbl to 2;
tbl.setAttribute("border", "2");
}
txtArr = [];
}
/////////// testing problems here /////////////////////
function testing() {
var i;
var lastCol = tbl.rows[0].cells.length - 1,
i, j;
// delete cells with index greater then 0 (for each row)
console.log(tbl.rows.length);
//while (tbl.hasChildNodes()) {
// tbl.removeChild(tbl.lastChild); // this line does not remove the last header
//}
for (i = 0; i < tbl.rows.length; i++) {
for (j = lastCol; j > lastCol - 1; j--) {
tbl.rows[i].deleteCell(j);
}
}
tbl.removeChild(thead); // this was updated
tbl.removeChild(th); // this was updated
// tbl.removeChild(tbl.firstChild); // this code remove only the first header
}
/////////// end of testing ////////////////////////////
function appendColumn() {
var i;
th = document.createElement('th');
th.innerHTML = "Sample";
tbl.appendChild(th);
tbl.appendChild(thead);
tbl.appendChild(tblBody);
// open loop for each row and append cell
for (i = 0; i < tbl.rows.length; i++) {
createCell(tbl.rows[i].insertCell(tbl.rows[i].cells.length), i, 'col');
}
}
// create DIV element and append to the table cell
function createCell(cell, text, style) {
var div = document.createElement('div'), // create DIV element
txt = document.createTextNode(text); // create text node
div.appendChild(txt); // append text node to the DIV
div.setAttribute('class', style); // set DIV class attribute
div.setAttribute('className', style); // set DIV class attribute for IE (?!)
cell.appendChild(div); // append DIV to the table cell
}
// delete table column with index greater then 0
function deleteColumn() {
var lastCol = tbl.rows[0].cells.length - 1,
i, j;
// delete cells with index greater then 0 (for each row)
console.log(tbl.rows.length);
for (i = 0; i < tbl.rows.length; i++) {
for (j = lastCol; j > lastCol - 1; j--) {
tbl.rows[i].deleteCell(j);
}
}
}
<!DOCTYPE html>
<html>
<head>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
<meta content="utf-8" http-equiv="encoding">
<title>Read Text File</title>
</head>
<body>
<input type="file" name="inputfile" id="inputfile">
<br>
<pre id="output"></pre>
<input type="button" value="Generate a table." onclick="generate_table()">
<input type="button" value="Add column" onclick="appendColumn()">
<input type="button" value="Delete column" onclick="deleteColumn()">
<input type="button" value="testing" onclick="testing()">
<table id="table">
</body>
</html>
prednisone without a prescription – generic prednisone 40mg price of prednisone 5mg
lasix definition
cost of advair prescription
can i order prednisone online
accutane purchase uk – accutane prescription canada accutane 2.5 mg
buy prednisolone acetate ophthalmic suspension usp 1
where to buy amoxicillin – order Amoxil buy amoxicilin
vardenafil generic drug – vardenafil online vardenafil vs cialis
ivermectin 500ml – ivermectin 3mg dose ivermectin 1
I’m extremely impressed with your writing skills and also with the layout
on your blog. Is this a paid theme or did you modify it yourself?
Anyway keep up the excellent quality writing, it is rare to see a nice blog like this one
today. http://www.deinformedvoters.org/hydroxychloroquine
generic cialis from uk – order cialis in canada tadalafil generic over the counter
Pretty section of content. I simply stumbled upon your weblog and in accession capital to claim
that I acquire actually enjoyed account your weblog
posts. Any way I’ll be subscribing on your augment and even I fulfillment you get right
of entry to consistently quickly. http://hydroxychloroquined.online/
stromectol 6mg online – stromectol buy uk
buy accutane 5mg – accutane pills price buy accutane from india
lyrica 150 – pharmacy near me legit online pharmacy
Interesting blog! Is your theme custom made or did you download it from somewhere?
A design like yours with a few simple tweeks would really make my blog stand out.
Please let me know where you got your theme. Thanks https://herreramedical.org/hydroxychloroquine
amoxicillin without a doctor‘s prescription – buy amoxicilin amoxil
generic viagra canada – viagra comparison prices no script viagra
ivermectin for sale – site ivermectin buy uk
provigil 100 mg – provgils modafinil moa
zpac – zithromax without a script zithromax 500
buy lasix tablets – furosemide iv buy furosemide 40mg tablets uk
order clomid – clomid 2020 generic clomid
Its like you learn my mind! You appear to understand so much about this, such as
you wrote the guide in it or something. I feel that you can do with a few percent to force the message home a bit, however other
than that, this is excellent blog. A great read.
I’ll certainly be back. http://antiibioticsland.com/Cephalexin.htm
After exploring a number of the blog articles on your web site, I honestly like your way of blogging.
I added it to my bookmark website list and
will be checking back soon. Please visit my website as well and let me
know how you feel. http://droga5.net/
where to buy propecia in malaysia
moxatag over the counter
is zithromax good for sinus infections
albuterol rx coupon
pharmacie annecy le vieux les tilleuls pharmacie aix en provence saint jerome , pharmacie de garde aujourd’hui ouverte pharmacie de garde beauvais oise , [url=https://kit.co/tires/fluoxetine-prix-sans-ordonnance-fluoxetine-pharmacie-suisse#]Fluoxetine prix sans ordonnance, Fluoxetine pharmacie Suisse[/url] therapie de couple lausanne [url=https://kit.co/certa/silvitra-prix-sans-ordonnance-silvitra-sans-ordonnance-quebec#]Silvitra sans ordonnance QuГ©bec[/url] , pharmacie avignon auchan pharmacie brest lafayette , pharmacie de garde suresnes. pharmacie geant casino therapies systemiques familiales [url=https://kit.co/specvir/torsemide-prix-sans-ordonnance-acheter-torsemide-20-mg-pas-cher#]Acheter Torsemide 20 mg pas cher[/url] , pharmacie en ligne dijon. pharmacie lafayette one nation, traitement uv pharmacie de garde aujourd’hui dijon . therapie quantique avis, pharmacie saint jacques beauvais therapies cognitivo-comportementales oms pharmacie bordeaux fac .
sildenafil and dapoxetine side effects
What’s up, this weekend is good in favor of me, as this occasion i am reading this wonderful
informative post here at my residence. http://herreramedical.org/azithromycin
can lisinopril make me feel sick
lisinopril prescribed for anxiety
cialis 5mg canada
best female viagra pills in india
how to get zithromax out of your system
stromectol oral
furosemide 40 mg price furosemide generic nek nox
lasix pill lasix online nek nox
furosemide 20 mg tablet buy online furosemide no prescription nek nox
cialis eli lilly
furosemide 40 lasix price nek nox
buy clomid online next day delivery
ivermectin 12 mg ivermectin lotion
lasix fluid retention
stromectol order online stromectol over the counter
lasix ivp
clomid for men for sale nek nox
stromectol tablets uk purchase oral ivermectin
ivermectin 3 mg tabs ivermectin 4000 mcg
stromectol tablete stromectol generic ivermectin 8000
can you buy prednisone over the counter uk – prednisone acetate prednisone 2.5 mg tab
isotretinoin for sale – buy accutane 10mg online accutane from canada pharmacy
generic plaquenil 200mg – cenforce for sale online order valacyclovir 500mg for sale
purchase sildalis online cheap – sildalis oral order glucophage
order ampicillin 250mg for sale – acillin usa buy plaquenil 400mg online cheap
buy generic plaquenil – brand plaquenil 200mg buy hydroxychloroquine 200mg pills
sildenafil en france – tadalafil 40mg generique en pharmacie pharmacie en ligne tadalafil 5mg
order prednisone 40mg – buy prednisone 10mg online cheap prednisone buy online
lyrica medication – furosemide 40mg pill buy azithromycin 500mg for sale
cheap cialis pills for sale tadalafil
tadalafil side effects tadalafil online
lowest price cialis tadalafil generic where to buy
tadalafil without a doctor prescription cialis without a prescription
cheapest tadalafil cost where to buy tadalafil on line
cialis cost side effects for tadalafil
tadalafil brands generic cialis online fast shipping
buy stromectol stromectol generic order stromectol online
http://stromectolusdt.com/ buying stromectol online