select with row id d3 js

Solutions on MaxInterview for select with row id d3 js by the best coders in the world

showing results for - "select with row id d3 js"
Eve
19 Aug 2017
1function tabulate(data, columns) {
2var table = d3.select("#container").append("table"),
3    thead = table.append("thead"),
4    tbody = table.append("tbody");
5
6// append the header row
7thead.append("tr")
8    .selectAll("th")
9    .data(columns)
10    .enter()
11    .append("th")
12        .text(function(column) { return column; });
13
14// create a row for each object in the data
15var rows = tbody.selectAll("tr")
16    .data(data)
17    .enter()
18    .append("tr");
19
20// create a cell in each row for each column
21var cells = rows.selectAll("td")
22    .data(function(row) {
23        return columns.map(function(column) {
24            return {column: column, value: row[column]};
25        });
26    })
27    .enter()
28    .append("td")
29        .text(function(d) { return d.value; });
30
31return table;
32}