I have the following code that shows without any problem a table of records generated from a json array.
$.each(query, function (name, value) {
fileTable +="<tr><td width='10%'><input type='text' name='fechaAsignacion' id='fechaAsignacion' value='"+value.fecha_asignacion+"' class='form-control' placeholder='01/01/2000'></td>"
fileTable +="<td width='30%'><select name='nuevoEstatus' id='nuevoEstatus' class='form-control select2'>";
@foreach($estatus as $estatu)
fileTable +="<option value='{{$estatu->id}}'>{{$estatu->nombre}}</option>"
@endforeach
fileTable = fileTable + "</select></td>"
fileTable +="<td width='50%'><input type='hidden' value='"+value.id+"' name='idEstatus'><textarea name='obs' id='obs' class='form-control'>"+value.observaciones+"</textarea></td>"
fileTable +="<td width='10%'><a class='btn btn-sm btn-warning' onClick='editarEstatus();'><i class='fa fa-pencil'></i></a> <a class='btn btn-sm btn-danger' onClick='eliminarEstatus();'><i class='fa fa-trash'></i></a></td></tr>
});
Now, the case is at the moment of capturing the information of each row, to edit it, always send me the first record, regardless of whether it is selecting 5, 6, 20, 28, 50 ...
In the editarUsuario()
function, I capture the data in row d as follows:
'idEstatus= $("#idEstatus").val();
nuevoEstatus = $("#nuevoEstatus").val();
fechaAsignacion = $("#fechaAsignacion").val();
obs = $("#obs").val();'
Table only in html
<table class='table table-condensed' id='tEstatus'>
<thead class='alert alert-info'>
<tr>
<th scope='col'>#</th>
<th scope='col'>Asignación</th>
<th scope='col'>Observaciones</th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<th scope='row'>1</th>"
<td width='10%'>
<input type='text' name='fechaAsignacion' value='"+value.fecha_asignacion+"' class='form-control' placeholder='01/01/2000'>
</td>"
<td width='50%'>
<input type='hidden' value='"+value.id+"' name='idEstatus'>
<textarea name='obs' class='form-control'>"+value.observaciones+"</textarea>
</td>"
<td>
<input type='button' id='editar' class='btn btn-sm btn-warning' value='Editar'>
</td>
</tr>
</tbody>
"
Any suggestions or what would be the best alternative to solve my doubt. Please !!!