Codeigniter数据表降序数据排序

时间:2017-02-02 03:55:59

标签: php jquery codeigniter datatable

我需要一些帮助,我在codeigniter中使用数据表。但我对订购数据有一些问题,我希望我的数据按ID表降序排序,但它不起作用。这是我的模型和数据表脚本

模型

 function select_blood()
{
    $this->db->order_by('blood_donor_id','desc');
    return $this->db->get('blood_donor')->result_array();
}

查看和数据表

 <?php foreach ($blood_donor_info as $row) { ?>   
        <tr>
            <td><?php echo $row['name'] ?></td>
            <td><?php echo $row['age'] ?></td>
            <td><?php echo $row['sex'] ?></td>
            <td><?php echo $row['blood_group'] ?></td>
            <td><?php echo date("m/d/Y", $row['last_donation_timestamp']) ?></td>
            <td>
                <a  onclick="showAjaxModal('<?php echo base_url();?>index.php?modal/popup/edit_blood_donor/<?php echo $row['blood_donor_id']?>');" 
                    class="btn btn-default btn-sm btn-icon icon-left">
                        <i class="entypo-pencil"></i>
                        Edit
                </a>
                <a href="<?php echo base_url();?>index.php?laboratorist/blood_donor/delete/<?php echo $row['blood_donor_id']?>" 
                    class="btn btn-danger btn-sm btn-icon icon-left" onclick="return checkDelete();">
                        <i class="entypo-cancel"></i>
                        Delete
                </a>
            </td>
        </tr>
    <?php } ?> <Script>jQuery(window).load(function ()
{
    var $ = jQuery;

    $("#table-2").dataTable({
        "sPaginationType": "bootstrap",
        "sDom": "<'row'<'col-xs-3 col-left'l><'col-xs-9 col-right'<'export-data'T>f>r>t<'row'<'col-xs-3 col-left'i><'col-xs-9 col-right'p>>",
    }); </script>

完整的js代码

<script type="text/javascript">
jQuery(window).load(function ()
{
    var $ = jQuery;

    $("#table-2").dataTable({
        "sPaginationType": "bootstrap",
        "sDom": "<'row'<'col-xs-3 col-left'l><'col-xs-9 col-right'<'export-data'T>f>r>t<'row'<'col-xs-3 col-left'i><'col-xs-9 col-right'p>>",
    });

    $(".dataTables_wrapper select").select2({
        minimumResultsForSearch: -1
    });

    // Highlighted rows
    $("#table-2 tbody input[type=checkbox]").each(function (i, el)
    {
        var $this = $(el),
                $p = $this.closest('tr');

        $(el).on('change', function ()
        {
            var is_checked = $this.is(':checked');

            $p[is_checked ? 'addClass' : 'removeClass']('highlight');
        });
    });

    // Replace Checboxes
    $(".pagination a").click(function (ev)
    {
        replaceCheckboxes();
    });
});

1 个答案:

答案 0 :(得分:0)

试试这段代码:

function select_blood()
{
    $this->db->from('blood_donor');
    $this->db->order_by("blood_donor_id", "desc");
    $query = $this->db->get();
    return $query->result_array();
}