I have a records in DataTable with a checkbox. I am trying to append new table to the row on clicking the checkbox. I am trying to do something like this.
Here they are taking values from row and formatting it and displaying back. But I have complete different table that I want to show.And I'm trying to achieve this with checkbox.
$('#tblEmployees').on('click', 'input[type="checkbox"].checkbox', function() {
var tr = $(this).closest('tr');
var Table = getTasks('Here I will pass my value to get Table through Ajax');
});
Now, I can display or hide when I check or un-check the checkbox.
Table Getting through Ajax
function getTasks(id) {
// Creating Inner table with little Styling
var table = $('<table width="90%" style="margin: 0 auto;">');
// Adding
var titleRow = $('<tr>');
titleRow.append('<th> Task # </th>');
titleRow.append('<th> Task Description </th>');
table.append(titleRow);
$.ajax({
url: '@Url.Action("GetTasks", "Programs")',
data: { id: id },
cache: false,
type: "GET",
success: function (data) {
$.each(data, function (key, value) {
var row = $('<tr>');
row.append('<td>' + value.TaskNo + '</td>');
row.append('<td>' + value.TaskDescription + '</td>');
table.append(row);
});
}
});
return table;
}