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)
3 Answers
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/
3 Comments
Gautier
can you provide a jsfiddle ?
Palmer Del Campo
"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> Vineela Thonupunuri
Just make sure to add the data-toggle at the table level, not tr or td
(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
Tyler2P
Your answer could be improved by adding more information on what the code does and how it helps the OP.