简体   繁体   中英

Add checkbox to table created CSV to HTML

I am currently building a prototype tool for my company. I am not too familiar with javascript but I did manage to find and implement a CSV to HTML table. The code works, and everything pulls fine, but I want to add two new variables:

1) add a checkbox in a new first column

2) if checked sum up the values in the 7th and 8th columns

This is the CSV to HTML demo: https://derekeder.github.io/csv-to-html-table/

Github: https://github.com/derekeder/csv-to-html-table

I have completed a search and found the following but I do not know if/how it can be implemented.

$(window).load(function(){
$("table td:first-child").prepend('<input type="checkbox" class="basic-kpi-    row"/>');
});//]]> 

You could add the td containing your checkbox after the row is created on your csv_to_html_table.js file, specificaly after this line .

It could be something like

row_html += '<td><input type="checkbox" class="yourClass"></td>';

Also you would have to add an aditional th tag on the thead row here

The you could add an event listener for the inputs in order to trigger your calculations.

$('.yourClass').change(function(){
    if (this.checked) {
        //your code
    }
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM