0

i need some help, i use datatable in codeigniter. but i've some problem with ordering data, i want my data is ordering descending by id table but it doesn't work . here is my model and datatable script

model

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

View and datatable

 <?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>

full js code

<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();
    });
});

2
  • Your model code seems correct. Just try to var-dump the result before use of Data table. May be Data table is causing problem. Commented Feb 2, 2017 at 4:03
  • your right sir, i've done it with this stackoverflow.com/questions/4964388/… Commented Feb 2, 2017 at 4:08

1 Answer 1

0

Try this code:

function select_blood()
{
    $this->db->from('blood_donor');
    $this->db->order_by("blood_donor_id", "desc");
    $query = $this->db->get();
    return $query->result_array();
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.