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)
Asked
Active
Viewed 3.5k times
7
-
Welcome to SO, please refer [mcve](http://stackoverflow.com/help/mcve) – bhansa Jan 19 '17 at 12:55
3 Answers
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
-
-
5"data-sort-name" needs to be used along with "data-field". for example: `
Date ` -
Just make sure to add the data-toggle at the table level, not tr or td – Vineela Thonupunuri Jul 08 '19 at 18:17
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
-
1Your 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