Sort datatable by date of records

Asked

Viewed 213 times

0

I have a code, which when starting, it creates a table using datatable. The data from this table comes from my Mysql database. I do not know for sure how is the ordering of my records, if I am not mistaken is coming by Id, but I need it to come ordered by date of each record.

In Mysql and codeigniter model (which I am using) I know how to do it, but when not using datatable. With him, I don’t know how I do it. My code as I said before is in Codeigniter.

The part that makes this table stays like this:

var oTable = $('#tabletools').dataTable({
        "sProcessing": '<?= $this->lang->line("datatable_process"); ?>',
        "bProcessing": true,
        "bServerSide": true,
        "bAutoWidth": true,
        "sAjaxSource": "<?php echo base_url() . $caminho; ?>",
        "fnDrawCallback": function (oSettings) {
            $("td:nth-child(1)").addClass('hidden-md hidden-sm hidden-xs');
            $("th:nth-child(1)").addClass('hidden-md hidden-sm hidden-xs');
            $("td:nth-child(4)").addClass('hidden-md hidden-sm hidden-xs');
            $("th:nth-child(4)").addClass('hidden-md hidden-sm hidden-xs');
            $("td:nth-child(5)").addClass('hidden-md hidden-sm hidden-xs');
            $("th:nth-child(5)").addClass('hidden-md hidden-sm hidden-xs');
            $("td:nth-child(6)").addClass('hidden-md hidden-sm hidden-xs');
            $("th:nth-child(6)").addClass('hidden-md hidden-sm hidden-xs');
            $("td:nth-child(7)").addClass('hidden-md hidden-sm hidden-xs');
            $("th:nth-child(7)").addClass('hidden-md hidden-sm hidden-xs');
            $("[rel=tooltip]").tooltip();
        },
        "oLanguage": {
            "sProcessing": "<?= $this->lang->line("datatable_process"); ?>",
            "sZeroRecords": "<?= $this->lang->line("datatable_records"); ?>",
            "sInfo": "<?= $this->lang->line("datatable_info"); ?>",
            "sInfoEmpty": "<?= $this->lang->line("datatable_empty"); ?>",
            "sInfoFiltered": "<?= $this->lang->line("datatable_filter"); ?>",
            "sInfoPostFix": "",
            "sUrl": "",
            "oPaginate": {
                "sFirst": "<?= $this->lang->line("datatable_first"); ?>",
                "sPrevious": "<?= $this->lang->line("datatable_previous"); ?>",
                "sNext": "<?= $this->lang->line("datatable_next"); ?>",
                "sLast": "<?= $this->lang->line("datatable_last"); ?>"
            }
        },
        "fnInitComplete": function (oSettings, json) {
            $(this).closest('#dt_table_tools_wrapper').find('.DTTT.btn-group').addClass('table_tools_group').children('a.btn').each(function () {
                $(this).addClass('btn-sm btn-default');
            });
            $("td:nth-child(1)").addClass('hidden-md hidden-sm hidden-xs');
            $("th:nth-child(1)").addClass('hidden-md hidden-sm hidden-xs');
            $("td:nth-child(4)").addClass('hidden-md hidden-sm hidden-xs');
            $("th:nth-child(4)").addClass('hidden-md hidden-sm hidden-xs');
            $("td:nth-child(5)").addClass('hidden-md hidden-sm hidden-xs');
            $("th:nth-child(5)").addClass('hidden-md hidden-sm hidden-xs');
            $("td:nth-child(6)").addClass('hidden-md hidden-sm hidden-xs');
            $("th:nth-child(6)").addClass('hidden-md hidden-sm hidden-xs');
            $("td:nth-child(7)").addClass('hidden-md hidden-sm hidden-xs');
            $("th:nth-child(7)").addClass('hidden-md hidden-sm hidden-xs');
        },
        'fnServerData': function (sSource, aoData, fnCallback) {
            aoData.push({name: '<?= $this->security->get_csrf_token_name() ?>', value: '<?= $this->security->get_csrf_hash() ?>'});
            aoData.push({name: "sSearch_1", value: iMin});
            aoData.push({name: "sSearch_2", value: iMax});
            $.ajax
                    ({
                        'dataType': 'json',
                        'type': 'POST',
                        'url': sSource,
                        'data': aoData,
                        'success': fnCallback
                    });

        }
    });
  • gives an order by in your query in mysql

  • @Marconi I have already tried to do this, but when putting order by some functions stopped working.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.