I have found out on the official page of Data Tables
how to do validations, but it seems very complex to me as for what I am doing.
The validation that I require is a bit similar to that done with PHP but in this case it is in a for cycle in JS handling the Data Tables
.
THE CODE:
var table_show = $('#table_students').DataTable({
"language": {
"sProcessing": "Procesando...",
"sLengthMenu": "Mostrar _MENU_ registros",
"sZeroRecords": "",
"sEmptyTable": "",
"sInfo": "Mostrando registros del _START_ al _END_ de un total de _TOTAL_ registros",
"sInfoEmpty": "Mostrando registros del 0 al 0 de un total de 0 registros",
"sInfoFiltered": "(filtrado de un total de _MAX_ registros)",
"sInfoPostFix": "",
"sSearch": "Consult Students:",
"sUrl": "",
"sInfoThousands": ",",
"sLoadingRecords": "Loading..",
"oPaginate":
{
"sFirst": "Primero",
"sLast": "Último",
"sNext": "Siguiente",
"sPrevious": "Anterior"
},
"oAria":
{
"sSortAscending": ": Activar para ordenar la columna de manera ascendente",
"sSortDescending": ": Activar para ordenar la columna de manera descendente"
}
},
});
list_data();
function list_data()
{
$.ajax({
url: 'calificaciones_estudiantes',
type: 'POST'
})
.done(function(result)
{
var answer= $.parseJSON(result);
if(answer.estado == "vacio")
{
var response = '<div class="alert alert-warning alert-dismissable">'
+ '<strong>¡Error!</strong>' + ' ' +answer.mensaje + '</div>';
$('#alert').html(response);
}
if(answer)
{
for (var i = answer.length - 1; i >= 0; i--)
{
var rowNode = table_show
.row.add([
answer[i].nombre_estudiante,
answer[i].fecha_calificacion,
answer[i].area,
answer[i].calificacion
])
.draw()
.node();
}
}
})
.fail(function() {
console.log("error");
});
}
WHAT IS REQUIRED:
A student may have different grades, so to "not lose" because they are many grades, I would like to validate if answer [i] .qualification="good" then show me the letters green for example, if it's bad to show me red ...
The problem is that I would not know how to do that validation in that case. I thank you in advance if you can help me.