score:2
Accepted answer
Possibly the easiest way to do this is to make your data
an array of Objects, instead of just an Array, e.g.
{id: 1, book: ["The Caves of Steel", "Isaac Asimov"], ...}
Then you can set the data-id
of each row using the id
attribute, and add td
s for the book
. Here's the code I used to get your example working:
// Add the header
thead.append("tr")
.selectAll("th")
.data(columns.slice(1, columns.length)) // skip the first column (IDs)
.enter()
.append("th")
.text(function ( d ) { return d; })
// Reformat the nested Arrays into an Array of Objects,
// then set the 'data-id' of each row
var rows = tbody.selectAll("tr")
.data(books.map(function(d){ return {id: d[0], book: d.slice(1, d.length)}; }))
.enter()
.append("tr").attr("data-id", function( d ){ return d.id; });
// Append the author and title for each book
var cells = rows.selectAll("td")
.data(function ( d ) { return d.book; })
.enter()
.append("td")
.text(function( d ) { return d; });
Source: stackoverflow.com
Related Query
- When creating an HTML table with D3, use certain data for a row class rather than cell
- Embedding csv in HTML for use with D3.js
- How to load data from an internal JSON array rather than from an external resource / file for a collapsible tree in d3.js?
- Why use element[0] instead of element when creating AngularJS directive with d3?
- D3 in Meteor is creating new shapes with updated data, rather than updating existing shape
- Parsing header row with dates when importing csv data
- Filter data by using checkbox for a table with D3.js
- Formatting data for use with JSON and D3.js
- Loading internal JSON data rather than from an external resource / file for a sunburst in d3
- Loading data from MySQL to use in D3 for creating line graph
- How to group HTML table entries with summary row above detail rows with D3
- d3.csv: using specific row data to use in a for loop argument
- When creating an HTML table in D3, how can I make the first column th
- d3js: Creating a collapsible table & issues with nested data
- Data model for creating a radial bar chart with d3js
- Appending multiple non-nested elements for each data member with D3.js
- How to use D3 selectAll with multiple class names
- Can i use d3.js for creating interactive visualizations inside an android app?
- How do I resolve "[ERR_REQUIRE_ESM]: Must use import to load ES Module" when using D3.js 7.0.0 with Next.js 11.0.1?
- Recursively (or iteratively) make a nested html table with d3.js?
- Using D3 transition method with data for scatter plot
- How to show c3.js No data but with legend for empty column?
- D3: use nest function to turn flat data with parent key into a hierarchy
- How can I perform this d3.js magic (Grouped Bar Chart) with JSON rather than CSV?
- Hitting browser "back" button shows JSON rather than HTML (using Rails & d3.js)
- D3.geo : Spherical arcs rather than straight lines for parallels?
- Drawing an HTML table via D3 doesn't update existing data
- D3 Tree Layout - Custom Vertical Layout when children exceed more than a certain number
- How can I use d3-scale-chromatic functions with a domain other than [0, 1]?
- Data for sunburst charts with d3.hierarchy using D3js v4
More Query from same tag
- How plot and symbolize only selected columns from csv in plotting in d3?
- Calculate averages to display in center of d3 donut chart
- Normalize numbers to 100 using D3 range?
- Migrating from D3.js V3 to V4 (and beyond) Error on svg.append
- D3.js multiple force layout graphs from json file
- Dynamic filtering with D3
- d3.js Color Groups for Radar Chart
- d3.event not working when combining modules
- data not bind from json for d3 chart
- Group bar chart data not working as expected
- how to make ticks function work in d3.js?
- DC charts - Customize ordinal x axis labels
- D3 JS Arch with Circle at border
- d3 Stacked Bar chart - assign olors
- How to use json data instead of tsv file in d3 multi line charts?
- how can set customize color to pie chart using D3.js?
- How can I alter the zooming capability on a d3 sunburst chart?
- d3: Make tick marks on d3.svg.axis draggable?
- LinkText is not working in tree layout d3js
- Explaining Mike Bostock's d3.js dragmove function
- How can I change the radius of a particular circle when clicking on a button?
- d3.geo.mercator displays shifted right in Chrome
- getting json data with d3.json() from php not working
- Form Input Event Listener
- Tooltips with canvas networks
- How to get a tooltip show up near the pie slice using d3.js?
- d3 re rendering chart exit is not a function
- How to label cities in a Geographical Map using D3.js?
- My svg path gets pixelation with d3
- How to list node_modules folders in a json/javascript file?