Skip to content

Commit d8241fd

Browse files
committed
setting nodeValue for create rows, clear by cloning the tbody
1 parent ddda7d7 commit d8241fd

File tree

1 file changed

+10
-5
lines changed
  • frameworks/keyed/vanillajs-2/src

1 file changed

+10
-5
lines changed

frameworks/keyed/vanillajs-2/src/Main.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ function _random(max) {
66

77
const rowTemplate = document.createElement("tr");
88
rowTemplate.innerHTML =
9-
"<td class='col-md-1'></td><td class='col-md-4'><a class='lbl'></a></td><td class='col-md-1'><a class='remove'><span class='remove glyphicon glyphicon-remove' aria-hidden='true'></span></a></td><td class='col-md-6'></td>";
9+
"<td class='col-md-1'> </td><td class='col-md-4'><a class='lbl'> </a></td><td class='col-md-1'><a class='remove'><span class='remove glyphicon glyphicon-remove' aria-hidden='true'></span></a></td><td class='col-md-6'></td>";
1010

1111
var rowId = 1;
1212
function buildData(count = 1000) {
@@ -120,6 +120,7 @@ class Main {
120120
}
121121
});
122122
this.tbody = document.getElementById("tbody");
123+
this.table = document.getElementsByTagName("table")[0];
123124
}
124125
run() {
125126
this.removeAllRows();
@@ -133,7 +134,7 @@ class Main {
133134
update() {
134135
for (let i = 0; i < this.data.length; i += 10) {
135136
this.data[i].label += " !!!";
136-
this.tbody.childNodes[i].firstChild.nextSibling.firstChild.firstChild.data = this.data[i].label;
137+
this.tbody.childNodes[i].firstChild.nextSibling.firstChild.firstChild.nodeValue = this.data[i].label;
137138
}
138139
}
139140
unselect() {
@@ -165,7 +166,7 @@ class Main {
165166
// var cNode = tbody.cloneNode(false);
166167
// tbody.parentNode.replaceChild(cNode ,tbody);
167168
// ~212 msecs
168-
this.tbody.textContent = "";
169+
// this.tbody.textContent = "";
169170

170171
// ~236 msecs
171172
// var rangeObj = new Range();
@@ -174,6 +175,10 @@ class Main {
174175
// ~260 msecs
175176
// var last;
176177
// while (last = tbody.lastChild) tbody.removeChild(last);
178+
179+
const clone = this.tbody.cloneNode();
180+
this.tbody.remove();
181+
this.table.insertBefore((this.tbody = clone), null);
177182
}
178183
runLots() {
179184
this.removeAllRows();
@@ -237,8 +242,8 @@ class Main {
237242
td1 = tr.firstChild,
238243
a2 = td1.nextSibling.firstChild;
239244
tr.data_id = data.id;
240-
td1.textContent = data.id;
241-
a2.textContent = data.label;
245+
td1.firstChild.nodeValue = data.id;
246+
a2.firstChild.nodeValue = data.label;
242247
return tr;
243248
}
244249
}

0 commit comments

Comments
 (0)