This is how I initialized jQuery datatables for sorting and paging in my code.
$("#tablepagination").dataTable( {
"bPaginate": true,
"sPaginationType": "full_numbers",
"bProcessing": true,
"bServerSide": true,
"iDisplayLength": <?php echo $_SESSION['record_count'];?>,
"sAjaxSource": "mod/get_contacts_con.php?type=c&is_con=1&sec=<?php echo $current_section_id;?>&con_id=<?php echo $con_id;?>",
"sServerMethod": "POST",
"sDom": '<"top font-style-4"fl<"topRecordInfo"i>p>rt<"bottom font-style-4"i><"clear">',
// Callback function added by sowjitha on 16, October 2015.
// To display the newly created id on search field
"fnDrawCallback": function(){
<?php if(isset($con_id) && !empty($con_id)){?>
$("#tablepagination tfoot th:first input").val('<?php echo $con_id;?>');
<?php }?>
},
"oLanguage": {
"sInfoFiltered": "",
"sProcessing": "<?php echo LBL_PROCESSING; ?>",
"sSearch": "<?php echo LBL_GLOBALSEARCH; ?>",
"sLengthMenu": "<?php echo LBL_SLENGTHMENU; ?>",
"sInfo": "<?php echo LBL_SINFO; ?>",
"sInfoEmpty": "<?php echo LBL_SINFOEMPTY; ?>",
"sInfoPostFix": "",
"sLoadingRecords": "<?php echo LBL_SLOADINGRECORDS; ?>",
"sZeroRecords": "<?php echo LBL_SZERORECORDS; ?>",
"sEmptyTable": "<?php echo LBL_SEMPTYTABLE; ?>",
"oPaginate":{
"sFirst": "<?php echo LBL_FIRST; ?>",
"sPrevious": "<?php echo LBL_PREVIOUS; ?>",
"sNext": "<?php echo LBL_NEXT; ?>",
"sLast": "<?php echo LBL_LAST; ?>"
},
"oAria": {
"sSortAscending": "<?php echo LBL_SSORTASCENDING; ?>",
"sSortDescending": "<?php echo LBL_SSORTDESCENDING; ?>"
}
},
"sAutoWidth": false,
/*"aoColumnDefs": [
{
"bSortable": false,
"aTargets": [ -1 ]
}
],*/
"aoColumns": [
null,
null,
null,
null,
null,
{"sClass": "datacontact5", "bSortable": false }
],
} );
Here, the sorting works fine for the first 2 columns. From the 3rd column, If I click on the 3rd column, it is sorting the second column. If I click on the 4th column, it is sorting the 3rd column and so on.
For more information, this is my html part
<thead>
<tr style="background-color:#b46a7a;color:#ffffff;">
<th class="id6td"><?php echo LBL_CONTACT_ID?></th>
<th class="nom6td"><?php echo LBL_CONTACT_LAST_NAME.' '.LBL_CONTACT_FIRST_NAME?></th>
<th class="email6td"><?php echo LBL_EMAIL?></th>
<th class="phone6td"><?php echo LBL_TEL?></th>
<th class="address6td"><?php echo LBL_ADDR?></th>
<th class="actions6td"><?php echo LBL_ACTIONS?></th>
</tr>
</thead>
I couldn't able to understand what is the issue with this code. Someone help me.
Most likely the issue is with your server-side PHP code. When server-side processing mode is enabled with bServerSide: true
, ordering/filtering/pagination is done on the server side. See Processing modes for more information.
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.