¿How can I add html rows to data table?
¿How can I add html rows to data table?
![morbius](https://secure.gravatar.com/avatar/549aceb0db6145c9225b805e84b98e41/?default=https%3A%2F%2Fvanillicon.com%2F549aceb0db6145c9225b805e84b98e41_200.png&rating=g&size=120)
I'm trying to add new html rows to data table when a user select one o more rows in other datatable and get the rows checked in second table to save it in database. The first time I can get it without problems, but if a select N rows in first table and added to second table, after select another N rows from first table and add these to second table, when I try to get the new resultset, only can get the first rows added to the second table.
The new N records not appear in the result string from table.serialize
I'm glad if any can help me. My code is:
//This is when the user select one o more rows in first table
$("#btnAddUser").click(function () {
var oTableX = $('#divTblSeaEmpList').dataTable();
sEmpsToAdd = oTableX.$('input').serialize();
if (sEmpsToAdd.length == 0) {
alert("\n - Selecciona al(los) empleado(s) que deseas agregar a la lista de participantes.");
}
else {
var cont = -1;
$("#divTblSeaEmpList input:checkbox").each(function () {
if ($(this).attr('id') != "chkAllSeaEmps" && $(this).is(':checked')) {
var iEmpPk = $(this).attr('id');
var iJobPk = $(this).val();
var bUsrExists = false;
$("#divTblEmpList input:checkbox").each(function () {
var iUsr = $(this);
if (iUsr.attr('id') == "Rchk" + iEmpPk) {
bUsrExists = true;
false;
}
});
if (!bUsrExists) {
$("#divTblEmpList tbody").append("<tr>" +
"<td class='chex-table'><input type='checkbox' checked='checked' onClick=UncheckAllRow(" + iEmpPk + "); name='Rchk" + iEmpPk + "' class='mc' value='" + iJobPk + "' id='Rchk" + iEmpPk + "'><label for='" + cont + "'></label></td>" +
"<td>" + $("#lblSap" + cont).html() + "</td>" +
"<td>" + $("#lblEmp" + cont).html() + "</td>" +
"<td class='chex-table'><input type='checkbox' onClick=ValidateMainCheck(" + iEmpPk + "); name='cho" + iEmpPk + "' class='mc' value='" + iJobPk + "' id='cho" + iEmpPk + "'><label for='" + cont + "'></label></td>" +
"<td class='chex-table'><input type='checkbox' onClick=ValidateMainCheck(" + iEmpPk + "); name='ctt" + iEmpPk + "' class='mc' value='" + iJobPk + "' id='ctt" + iEmpPk + "'><label for='" + cont + "'></label></td>" +
"</tr>");
}
}
cont++;
});
}
oTableX.fnDestroy();
$("#divTblSeaEmpList tr:gt(0)").remove();
});
//This is when I try to get all rows added to second table
$("#btnGetUsersAdded").click(function () {
var oSecTable = $('#divTblEmpList').dataTable();
sEmpsSelected = oSecTable.$('input').serialize();
});
Thanks for your help