7

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)

camelCaseCoder
  • 1,447
  • 19
  • 32
MSG3260
  • 79
  • 1
  • 1
  • 2

3 Answers3

24

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/

Gautier
  • 1,066
  • 1
  • 13
  • 24
0

You can use

    defaultSorted={[{
             dataField: 'FIELD_NAME',
             order: 'asc'}]}
              
Ria
  • 1
  • 4
0

(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

Allen
  • 1
  • 1
    Your answer could be improved by adding more information on what the code does and how it helps the OP. – Tyler2P Jan 25 '22 at 16:20