Datatables "order" isn't working

Datatables "order" isn't working

hanmumuhanmumu Posts: 5Questions: 2Answers: 0

My table is filled by HTML code. And it was working fine!

But now I want to sort by the 4th column and it's just ignoring me x(
I checked and the code is there, but nothing happens.

Do know know what might be wrong?
Thank you in advance!

$j('#table_doc').DataTable({

            "dom": "<'#dtdiv1.row'<'#leng1.col-sm-3'l><'#pag1.col-sm-6'p><'#searchBox1.col-sm-3'f>>" +
                "<'row'<'col-sm-12'tr>>" +
                "<'#dtdiv2.row'<'#leng2.col-sm-3'l><'#pag2.col-sm-6'p><'#searchBox2.col-sm-3'f>>",

            "language": {
                "url": "//cdn.datatables.net/plug-ins/9dcbecd42ad/i18n/Portuguese.json",
            },

            "stateSave": "true",

            "order": [[3, "desc" ]],

            "fnStateSave": function(oSettings, oData) {
                localStorage.setItem('DataTables_' + window.location.pathname, JSON.stringify(oData));
            },
            "fnStateLoad": function(oSettings) {
                var data = localStorage.getItem('DataTables_' + window.location.pathname);
                return JSON.parse(data);
            },


            "stateLoadParams": function (settings, data) {
                return true;

            },
            fnInitComplete: function() {

                $("#table_doc").wrap("<div style='overflow:auto; width:100%;position:relative;'></div>");

                $('#dtdiv1').attr("align", "center");
                $('#leng1 label').attr("style", "width:70px; margin-top:5px; margin-left:30px;");
                $('#searchBox1 label').attr("style", "margin-top:5px;margin-right:30px;");
                $('#pag1').attr("style", "z-index:1;");

                $('#dtdiv2').attr("align", "center");
                $('#leng2 label').attr("style", "width:70px; margin-top:5px; margin-left:30px;");
                $('#searchBox2 label').attr("style", "margin-top:5px;margin-right:30px;");
                $('#pag2').attr("style", "z-index:1;");

            },
            drawCallback: function() {

            }

        });

Answers

  • kthorngrenkthorngren Posts: 21,343Questions: 26Answers: 4,954

    test by turning StateSave off. If the problem you are asking about is with the initial Datatable load then stateSave is likely picking up changes in the column ordering by the user. Is this what you are asking about?

    Or is it that ordering the 4th column isn't working as expected. If this is the case then we will need to see your page or a test case replicating the data and issue in order to see what is happening.

    Kevin

This discussion has been closed.