I have one table.Inside table I have two <td>.First <td> has one checkbox and second <td> has sections which also contains checkboxes.Onclick of checkbox of first <td>,it should check all the checkboxes of other <td>.This is the code which is using datatable.
for (var i = 0; i < tmpColumns.length; i++) {
var obj = new Object();
var table = "";
obj.title = tmpColumns[i].toUpperCase();
obj.data = tmpColumns[i];
obj.defaultContent = "";
columns.push(obj);
if(type == "table" && i == 0) {
obj.render = function (data, type, row, meta) {
table = row.name;
select = '<section> <label class="checkbox" style="padding-left: 1em;"><input type="checkbox" id = "checkAll" " data-table-name="' + table + '">' + table + ' <i></i></label></section>';
return select;
}
}
if(type == "table" && i == 1) {
obj.render = function (data, type, row, meta) {
table = row.name;
for (var j = 0; j < data.length; j++) {
var column = table + "." + data[j];
ele = ele + '<section> <label class="checkbox" style="padding-left: 1em;"><input type="checkbox" class="addToQuery" data-col="' + column + '" data-table="' + table + '"><i></i>' + data[j] + '</label></section>';
}
return ele;
};
break;
}
}
This is the code for checking checkbox after clicking first checkbox.
$("#tableList").on("change",'input[data-table-name]', function () {
var bool = $(this).prop('checked');
var tableName = $(this).attr("data-table-name");
$('input[data-table="' + tableName + '"]').prop("checked", bool);
});
I want to check the particular checkbox in which is in the same <tr>.But it is checking all the <tr> elements
Thanks.
$(this).closest('tr').siblings().find('input[data-table="' + tableName + '"]').prop("checked", bool);Bettter to post generated markup too.