这是我在代码中初始化jQuery数据表以进行排序和分页的方法。
$("#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 }
],
} );
这里,排序适用于前2列。从第3列开始,如果单击第3列,则会对第2列进行排序。如果我点击第4列,它会对第3列进行排序,依此类推。
有关详细信息,这是我的html部分
<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>
我无法理解此代码的问题。有人帮助我。
答案 0 :(得分:1)
很可能问题出在您的服务器端PHP代码上。当使用bServerSide: true
启用服务器端处理模式时,在服务器端完成排序/过滤/分页。有关详细信息,请参阅Processing modes。