Buen dia
Les pido una disculpa si el tieulo de la pregunta no es el mas apropiado, pero no se me ocurrio algun otro
Tengo el siguiente problema:
Etoy trabajando con la siguiente dataTble:
Este es my codigo html de dicha tabla:
<table id="table" class="table table-hover">
<thead>
<tr class="primary">
<th></th>
<th hidden class="idRequest">idRequest</th>
<th>Solicitante</th>
<th>Dia de solicitud</th>
<th>Estatus</th>
<th>Acciones</th>
</tr>
</thead>
</table>
Cuando hago click en el boton verde señalado en la imagen con una flecha y un recuadro rojo muestro una subTabla con datos de mi registro. esta accion la reralizo con el siguiente codigo de Jquery:
// Add event listener for opening and closing details
$('#table tbody').on('click', 'td.details-control', function () {
var tr = $(this).closest('tr');
var row = table.row(tr);
if (row.child.isShown()) {
// This row is already open - close it
row.child.hide();
tr.removeClass('shown');
}
else {
// Open this row
row.child(format(row.data())).show();
tr.addClass('shown');
}
});
A continucion les muestro mi funcion format(row.data()) [Es aqui donde se presenta mi problema]:
function format(d) {
var buttons = '';
subTable = '<table>'
getRequeriments(d.request.idRequest).then(data => {
data.forEach(element => {
if (d.status == 'En Proceso' && element.fkTypesStatus == 1 &&
(d.request.wiwResponsable.trim().toLowerCase() == '@Request.Cookies["PFEPCoockie"]["wiw"].ToLower()'
|| @Request.Cookies["PFEPCoockie"]["idRole"] < 4)) {
buttons = '<button class= "btn btn-success btn-circle realizado" title="Realizado"> <i class="material-icons">done</i></button>' +
" " +
'<button class= "btn btn-danger btn-circle noRealizado" title="Rechazar"> <i class="material-icons">close</i></button>'
} else if (d.status == 'En Proceso' && element.fkTypesStatus == 3 &&
(d.request.wiwResponsable.trim().toLowerCase() == '@Request.Cookies["PFEPCoockie"]["wiw"].ToLower()'
|| @Request.Cookies["PFEPCoockie"]["idRole"] < 4)) {
buttons = '<h6 class ="text-success">REALIZADO</h6>';
} else if (d.status == 'En Proceso' && element.fkTypesStatus == 5 &&
(d.request.wiwResponsable.trim().toLowerCase() == '@Request.Cookies["PFEPCoockie"]["wiw"].ToLower()'
|| @Request.Cookies["PFEPCoockie"]["idRole"] < 4)) {
buttons = '<h6 class ="text-danger">NO REALIZADO</h6>';
}
subTable += '<tr>' +
'<th hidden>' + 'ID' + '</th>' +
'<th hidden>' + 'idReq' + '</th>' +
'<th>' + 'Numero de parte' + '</th>' +
'<th>' + 'Pool' + '</th>' +
'<th>' + 'Estacion' + '</th>' +
'<th>' + 'SA1' + '</th>' +
'<th>' + 'SA2 Actual' + '</th>' +
'<th>' + 'SA2 Solicitado' + '</th>' +
'<th>' + 'Razon' + '</th>' +
'<th>' + 'Estatus' + '</th>' +
'</tr>' +
'<tr>' +
'<td hidden class ="id">' + element.idRequisition + '</td>' +
'<td hidden class ="idReq">' + d.request.idRequest + '</td>' +
'<td>' + element.itemNumber + '</td>' +
'<td>' + element.pool + '</td>' +
'<td>' + element.station + '</td>' +
'<td>' + element.SA1 + '</td>' +
'<td>' + element.lastSA2 + '</td>' +
'<td>' + element.currentSA2 + '</td>' +
'<td>' + element.reason + '</td>' +
'<td class ="buttons">' + buttons + '</td>' +
'</tr>'
});
subTable += '</table>'
});
return subTable;
}
Esta es la funcion que mando a llamar para obtener los datos de mi sub tabla:
async function getRequeriments(idRequest) {
const requeriments = await $.ajax({
url: "@Url.Action("getRequeriments", "verRequest")",
type: 'post',
datatype: 'application/json',
data: {
'idRequest': idRequest
}
});
return requeriments;
}
Ya habia echo algo similar pero sin utilizar una funcion async, el problema es que cuando lo hago con la funcion async no me muestra los datos.
Es la primera vez que utilizo este tipo de funciones y la verdad nose como funcionan exactamente, podrian ayudarme con este problema