I have this table:
<table id="datatable" class="table table-striped table-bordered">
<thead>
<tr>
<th>ID</th>
<th>Agent</th>
<th>TWWID</th>
<th>Start Date</th>
<th>Issue</th>
<th>Comment</th>
<th>Overview</th>
<th>Action</th>
<th>TL</th>
<th>Qfinity ID</th>
<th>MSISDN</th>
</tr>
</thead>
<tbody>
<?php
//get records from database
$sql_list = "SELECT * FROM `coaching`";
$sql_list_result = $mysqli->query($sql_list);
if($sql_list_result->num_rows > 0){
while($row = $sql_list_result->fetch_assoc()){ ?>
<tr>
<td><?php echo $row['ID']; ?></td>
<td><?php echo $row['Agent']; ?></td>
<td><?php echo $row['TWWID']; ?></td>
<td><?php echo $row['Start_Date']; ?></td>
<td><?php echo $row['Issue']; ?></td>
<td><?php echo $row['Comment']; ?></td>
<td><?php echo $row['Overview']; ?></td>
<td><?php echo $row['Action']; ?></td>
<td><?php echo $row['TL']; ?></td>
<td><?php echo $row['Qfinity_ID_1']; ?></td>
<td><?php echo $row['MSISDN']; ?></td>
</tr>
<?php } }else{ ?>
<tr><td colspan="5">Nema brojeva u bazi.....</td></tr>
<?php } ?>
</tbody>
</table>
In this table i have sortable heders and first column is defoult sorted ASC, but i want the 3'rd column to be sorted by default DESC.
I include in my .php this js (//cdn.datatables.net/1.10.18/js/jquery.dataTables.min.js)
then I add in .php this script
<script>
$(document).ready(function() {
$('#datatable').DataTable( {
"aaSorting": [[ 3, "desc" ]]
} );
} );
</script>
My table still have sort by 1'st column [ID]
how can i change default sorting?
I faced the same problem and I solved it with the following code. Please try if it can help:
<script>
$(document).ready(function() {
$('#datatable').DataTable( {
"order": [[ 3, "desc" ]]
});
});
</script>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.