how to highlight a row in Table.

212 views
Skip to first unread message

hai2...@gmail.com

unread,
Jun 7, 2013, 7:35:21 AM6/7/13
to d3...@googlegroups.com
Hi,

I would like to highlight a row in a table. For e.g when i click on a row, the row background color needs to be changed. How do i do that in d3?

thanks,

Jason Davies

unread,
Jun 7, 2013, 8:55:49 AM6/7/13
to d3...@googlegroups.com
On Fri, Jun 07, 2013 at 04:35:21AM -0700, hai2...@gmail.com wrote:
> I would like to highlight a row in a table. For e.g when i click on a row,
> the row background color needs to be changed. How do i do that in d3?

You could define a "highlight" CSS class:

.highlight {
background: #f00;
}

Then, attach a "click" handler to each <tr> element (table row):

var tr = table.selectAll("tr")
.on("click", function() {
// Remove "highlight" class from all rows.
tr.classed("highlight", false);
// Add highlight class to this row.
d3.select(this).classed("highlight", true);
});

--
Jason Davies, http://www.jasondavies.com/
Reply all
Reply to author
Forward
0 new messages