I want to add a checkbox to each row of a table. All will be selected originally, then have the ability to check/uncheck to filter the rows of data.
There is a similar question here but I don't know how to implement. I'm a bit of a newbie here.
Here is my code that generates the table:
function init() {
// Get scenario names
var selector = d3.select("#selDataset");
// d3.csv("data/final/hou_scenarios.csv").then(annualData => {
// console.log(annualData);
// console.log(annualData[0]["Scenario"]);
// Populate the annual table
d3.csv("data/final/hou_annual_data.csv").then(annualData => {
console.log("ANNUAL DATA");
console.log(annualData);
console.log(annualData[0]["Scenario"]);
var tableAnnualData = annualData;
// reference table body
var tbody = d3.select("tbody");
// use Arrow Functions to loop through the object (each dictionary) "scenario" and append to table row
// use fat arrow method to iterate over objects and then the key:value pairs
annualData.forEach((scenario) => {
var row = tbody.append("tr");
Object.entries(scenario).forEach(([key, value]) => {
var cell = row.append("td");
cell.text(value);
});
// verify objects
console.log("VERIFY LOOPED DATA");
console.log(scenario);
});
var scenarios = annualData.map(o => o.Scenario)
console.log("SCENARIO NAMES");
console.log(scenarios);
scenarios.forEach(scenario => {
selector.append("option")
.text(scenario)
.property("value", scenario);
});
});
}
init();
The table is rendering just fine. What I want to do is add checkboxes next to the first column to be able to turn rows on/off from displaying.
Any suggestions on what to do? The checkboxes could be the first table row. Or they could be in there own css container, though I would prefer them as part of the table.