3

I want to sort records in descending order. Here my code:

Jquery:

<script type="text/javascript" charset="utf-8">
var j = jQuery.noConflict();
j(document).ready(function() {`enter code here`
    oTable = j('#example').dataTable({
        "bJQueryUI": true,
        "sPaginationType": "full_numbers"
    });
});
</script>

My Sql query is:

$select="select * from users_tbl order by User_ID desc ";

2 Answers 2

12

Add this attribute to your table data-order='[[ 0, "desc" ]]' if you want to order the results in descending order in the first column.

Example:

<table data-order='[[ 0, "desc" ]]' data-page-length='25'>
    <thead>
        <tr>
            <th>ID</th>
            <th>Name</th>
            <th>Position</th>
            <th>Office</th>
            <th>Age</th>
            <th>Start date</th>
            <th data-class-name="priority">Salary</th>
        </tr>
    </thead>
</table>

Will give you results with ID in descending order. Just like an array, 0 means the first column, 1 means the second columns... and so on.

Sign up to request clarification or add additional context in comments.

1 Comment

Perfect for me!
1

Richie. Thanks for your help.

It worked for me in "Start Bootstrap - SB Admin 2 v4.1.3"

<table class="table table-bordered" id="dataTable" width="100%" cellspacing="0" data-order='[[ 0, "desc" ]]' data-page-length='20'>

1 Comment

Please don't add "thank you" as an answer. Once you have sufficient reputation, you will be able to vote up questions and answers that you found helpful. - From Review

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.