8

I using bootstrap table and there is a default sorting of first column. How can I change default column and choose another and using (Ascending/Descending)

1
  • Welcome to SO, please refer mcve Commented Jan 19, 2017 at 12:55

3 Answers 3

25

You can use data-sort-name and data-sort-order in your table

For example :

<table data-toggle="table" data-sort-name="date" data-sort-order="desc">

The documentation is here http://bootstrap-table.wenzhixin.net.cn/documentation/

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

3 Comments

can you provide a jsfiddle ?
"data-sort-name" needs to be used along with "data-field". for example: <table data-toggle="table" data-sort-name="date" data-sort-order="desc"> <th data-field="date">Date</th>
Just make sure to add the data-toggle at the table level, not tr or td
1

(May be it's too late to answer but just trying to help the other.) Try to add this in your script

<script type="text/javascript">
$(document).ready(function() {
    $('#table_id').DataTable( {
        "order": [[ 1, "desc" ]]
    } );
} );

Reference: https://datatables.net/examples/basic_init/table_sorting.html

1 Comment

Your answer could be improved by adding more information on what the code does and how it helps the OP.
0

You can use

    defaultSorted={[{
             dataField: 'FIELD_NAME',
             order: 'asc'}]}
              

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.