Weird sorting behaviour ... sorting the column before
Weird sorting behaviour ... sorting the column before
AfonsoGomes
Posts: 1Questions: 1Answers: 0
Sorting works on the 4th column ("Flor") ... but after that the column "Descritor" (5th) sorts the column data "Flor" (4th) ... column "T. Fisio" (6th) sorts "Descritor" (5th) and so on ... what's wrong with my code? Been struggling with this for a bit!
```js
function especiesTodasCallback( nRow, aData, iDisplayIndex ) {
$('td:eq(1)', nRow).html( '<a href="especies.php?idEspecie=' + aData[0] + '">' + aData[1] + '</a>' );
if (aData[2] != 1) {
$('td:eq(2)', nRow).html('<span class="cor-ad"><b>N</b></span>');
} else {
$('td:eq(2)', nRow).html('<span class="cor-jb">S</span>');
}
if (aData[3] == null) { aData[3] = "" }
if (aData[4] == null) { aData[3] = "" }
if (aData[3] != "" && aData[4] != "") {
$('td:eq(3)', nRow).html( aData[3] + ' - ' + aData[4] );
} else {
$('td:eq(3)', nRow).html('<span class="cor-ad"><b>ND</b></span>');
}
if (aData[6] == null) {
$('td:eq(4)', nRow).html('<span class="cor-ad"><b>ND</b></span>'); // aData[5] --> idDescritor
} else {
$('td:eq(4)', nRow).html(aData[6]);
}
$('td:eq(5)', nRow).html( aData[8] ); // aData[7] -> idTFis
$('td:eq(6)', nRow).html( aData[10] ); // aData[9] -> idFam
$('td:eq(7)', nRow).html( aData[12] ); // aData[11] -> idOrdem
$('td:eq(8)', nRow).html( aData[14] ); // aData[13] -> idSubClasse
$('td:eq(9)', nRow).html( aData[16] ); // aData[15] -> idClasse
$('td:eq(10)', nRow).html( aData[18] ); // aData[17] -> idSubDivisao
$('td:eq(11)', nRow).html( aData[20] ); // aData[19] -> idDivisao
return nRow;
}
$(document).ready(function() {
$('#especies-todas').DataTable({
"sAjaxSource": '../php/admin_motor.php?act=especie_get_all',
"sAjaxDataProp": "data",
"aoColumns": [
{ sTitle:'iD', sWidth:'25px' },
{ sTitle:'Espécie' },
{ sTitle:'<i class="fa fa-eye"></i>', sWidth:'15px' },
{ sTitle:'Flor.' },
{ sTitle:'Descritor'},
{ sTitle:'T. Fisio.' },
{ sTitle:'Família' },
{ sTitle:'Ordem' },
{ sTitle:'Sub-Classe' },
{ sTitle:'Classe' },
{ sTitle:'Sub-Divisão' },
{ sTitle:'Divisão' }
],
"bProcessing": true,
"colReorder": true,
"fnRowCallback": especiesTodasCallback,
"order": [[0, "asc"]],
"language": {"url": "js/dataTables.portugues.js"},
"buttons": [
{ extend: 'excelHtml5', text: 'Excel', exportOptions: { columns: ':visible' }, className: 'btn-sm' },
{ extend: 'csvHtml5', text: 'CSV', exportOptions: { columns: ':visible' }, className: 'btn-sm' },
{ extend: 'copyHtml5', text: 'Copiar', exportOptions: { columns: ':visible' }, className: 'btn-sm' },
{ extend: 'print', text: 'Imprimir', exportOptions: { columns: ':visible' }, className: 'btn-sm' },
{ extend: 'colvis', text: 'Ver Colunas', className: 'btn-sm btn-vercolunas' },
{ extend: 'excelHtml5',text:'Excel (esta pag)',className:'btn-sm',exportOptions:{columns:':visible',modifier:{page:'current'}}},
{ extend: 'copyHtml5',text:'Copiar (esta pag)',className:'btn-sm',exportOptions:{columns:':visible',modifier:{page:'current'}}},
{ extend: 'csvHtml5', text: 'CSV (esta pag)',className: 'btn-sm',exportOptions:{columns:':visible',modifier:{page:'current'}}},
{ extend: 'print', text: 'Imprimir (esta pag)', className: 'btn-sm',exportOptions:{columns:':visible',modifier:{page:'current'}}}
],
"dom": '<"row"<"col-md-8"B><"col-md-4"f>r><"row"<"col-md-12"t>><"row"<"col-md-6"i><"col-md-6"lp>>',
"fnDrawCallback": function(){
DTclickable();
DTlengthSelect();
obtem_tamanho();
},
"fnInitComplete": function(oSettings) {
oSettings.oLanguage.sZeroRecords = "Não foram encontrados resultados"
}
});
});
This discussion has been closed.