Hello
I made a generic JavaScript function that needs to receive a DataTable as a parameter, but for some reason it is not getting the data from this DataTable.
This function is called when the user clicks the DataTable cell
$('#tableBaseHour').on('click', 'tbody td', function () {
ClickTables('#tableBaseHour', $('#tableBaseHour thead th').length);
});
I will have all 12 DataTables in the same screen, so for this reason I need a generic function that takes only the id of the DataTable and does the function. The function is this:
function ClickTables(clickTable, lengthCols) {
var table = $(clickTable).DataTable();
var colIndex = table.column($(this).closest('td')).index();
var rowclicked = table.row($(this).closest('td')).index();
//SE A LINHA CLICADA NÃO ESTÁ DENTRO DA ÁREA DE CAMPOS QUANTITIES
if (table.rows().count() == table.row($(this).closest('tr')).index() ||
colIndex == lengthCols - 1 || colIndex == 0 || rowclicked == 12) {
return;
}
//SE A CÉLULA CLICADA ESTÁ DENTRO DA ÁREA DE CAMPOS QUANTITIES E É HABILITADA À EDIÇÃO
else {
var row = table.row($(this).closest('tr')).index();
//ABRE A MODAL DE EDIÇÃO DO CAMPO
$('#newBHUnit').modal('show');
$('#YearId').prop('disabled', true);
$('#Month').prop('disabled', true);
$("#InputTypeId").prop('disabled', true);
$("#AnalyzeTypeId").prop('disabled', true);
$("#LowTierId").prop('disabled', true);
//CHAMA A FUNÇÃO QUE REALIZA O EDIT
EditBaseHour(table.column(colIndex).title, $('#findYearBH').val(), row + 1);
}
}
This function is taking the information from the field, playing to a Modal and allowing editing of the record in it.
When the function was applied directly inside the on click functioned perfectly, but for some reason within the method it does not work (the data passed in Edit that depends on the DataTable information goes null and the function of the Edit is not performed).
Could anyone help me with this?