change value of a cell after DataTables() has been applied
change value of a cell after DataTables() has been applied
Consider the following code
function toggleCheckMark(elem, brand){
var cell = $(elem).html();
if(cell == ""){
$(elem).html("✔");
var brandval = parseInt($("#" + brand).find("td:eq(3)").html());
var newval = brandval + 1;
$("#" + brand).find("td:eq(3)").html("" + newval + "");
} else {
$(elem).html("");
var brandval = parseInt($("#" + brand).find("td:eq(3)").html());
var newval = brandval - 1;
$("#" + brand).find("td:eq(3)").html("" + newval + "");
}
}
This toggles the existence of a check mark character in a table cell which is a DataTables table.
I also have a 2nd table which summarizes some of the info in the first.
Let cell
be the cell in table 1 which we have just clicked and added or removed a checkmark.
Let "#" + brand
be the id of the table row in the summary table (table2).
I want to increment the value in td
offset 3 (column 4), however when I have called .DataTables();
on table 2, my reference to the cell returns undefined.
My objective is to increment or decrement the value by 1. How can I achieve this after I have applied the .DataTables()
method to my table.
Many Thanks
Answers
This FAQ explains it. In short you need to use the DataTables API if you want to change the table - you can do that with
cell().data()
in this case.Allan