DataTable with Absolute plugin changed the type of the column, ordering wrong

DataTable with Absolute plugin changed the type of the column, ordering wrong

daniloragodanilorago Posts: 2Questions: 1Answers: 0

I am using DataTable to present the information in my table, but at a certain point I needed to add a line at the top, for this in my research I saw that there is the Absolute plugin. After that I was able to leave the specific line at the top, when necessary, using the first column (ID), of which all numbers are integers. However, when using this plugin, check that it transforms the field from INT to STRING, thus ordering the rest of the table incorrectly, as shown below:

ID 8 Fixed, ordering the rest on ID DESC:

ID 8 Fixed, ordering the rest on ID ASC:

Then the result is that is ordering as String, not as Int (Number).

CODE:

$(document).ready(function(){
    var Str__ID = $.fn.dataTable.absoluteOrder([
        {
            position: 'top',
            value: '8'
        }
    ]);
    $.fn.dataTable.moment('DD/MM/YYYY');
    $('#DT__List').DataTable({
        "dom": 'lBfrtip',
        "columnDefs": [{
            "orderable":    false,
            "targets":      [3]
        },{
            "type":     Str__ID,
            "targets":  [0]
        }],
        "info":             true,
        "fixedHeader":      true,
        "language": {
            "aria": {
                "sortAscending":    ": ativar para classificar a coluna ascendente",
                "sortDescending":   ": ativar para classificar a coluna descendente"
            },
            "buttons": {
                "copy":             "Copiar",
                "copySuccess": {
                    _:              "( %d ) linhas copiadas para a área de transferência!",
                    1:              "( 1 ) linha copiada para a área de transferência!"
                },
                "copyTitle":        "Copiar",
                "csv":              "CSV",
                "excel":            "Excel",
                "pdf":              "PDF",
                "print":            "Imprimir"
            },
            "emptyTable":           "Não há registro(s)!",
            "info":                 "Página _PAGE_ de _PAGES_",
            "infoEmpty":            "Não há registro(s)!",
            "infoFiltered":         " (Do total de _MAX_ registro(s))",
            "lengthMenu":           "Mostrar _MENU_ registro(s) em cada página",
            "loadingRecords":       "Carregando…",
            "paginate": {
                "first":            "Primeira",
                "last":             "Última",
                "next":             "Próxima",
                "previous":         "Anterior"
            },
            "processing":           "Processando…",
            "search":               "Pesquisar:",
            "searchPlaceholder":    "Pesquisar…",
            "zeroRecords":          "Opsss, não encontramos nada através da sua pesquisa!"
        },
        "order":        [[0,"desc"]],
        "ordering":     true,
        "pageLength":   10,
        "paging":       true,
        "select":       true
    });
});

I even tried to change the column by code, but without success:

{
    "type":     "num",
    "targets":  [0]
}

Anyone solved this error?
I made a big search, but nobody asked that...

This question has an accepted answers - jump to answer

Answers

Sign In or Register to comment.