For example, in a html <table>
, a <tr>
may contain <th>
and <td>
. How would you bind data to a row selection that would create even columns as <th>
and odd as <td>
?
So, this doesn't seem perfect either, but there's always the html() method.
var d = [['a','b','c','d']];
var r = d3.select('#myTable').selectAll('tr')
.data(d);
r.enter().append('tr').html(function(d) {
var i, s = '';
for (i = 0; i < d.length; i += 1) {
s += (i%2===0) ? '<th>' : '<td>';
s += d[i];
s += (i%2===0) ? '</th>' : '</td>';
}
return s;
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With