Selections in D3 are immutable. Therefore, this:


... won't change what tr is. Since you obviously want it to be the "update + enter" selections, you have to reassign it:

tr = tr.merge(tr.enter().append("tr"));

Finally, I'd advise naming the enter selection, so the whole thing would be:

var trEnter = tr.enter().append("tr");
tr = tr.merge(trEnter);

Related Query

More Query from same tag