因爲表格比較長客戶要求左側的部分列要固定,以及頭部固定,並有搜索排序功能,找了很久終於找到一個比較好的插件,DataTable,網站:https://datatables.net/download/index,因爲我用的是bootstrap風格的,就下載一樣風格的DataTable樣式,主要有3個樣式文件javascript
<link rel="stylesheet" href="../../bootstrap/css/bootstrap.min.css"> <link rel="stylesheet" href="../../plugins/datatables/dataTables.bootstrap.css"> <link rel="stylesheet" href="../../plugins/datatables/extensions/FixedColumns/css/fixedColumns.bootstrap.min.css">
以及幾個js文件以及配置方法css
<script src="../../plugins/jQuery/jQuery-2.1.4.min.js"></script> <!-- Bootstrap 3.3.5 --> <script src="../../bootstrap/js/bootstrap.min.js"></script> <!-- DataTables --> <script src="../../plugins/datatables/jquery.dataTables.min.js"></script> <script src="../../plugins/datatables/dataTables.bootstrap.min.js"></script> <script src="../../plugins/datatables/extensions/FixedColumns/js/dataTables.fixedColumns.min.js"> </script> <script type="text/javascript"> $(document).ready(function() { var table = $('#example').DataTable( { scrollY: "500px", scrollX: true, scrollCollapse: true, paging: false, info: false, oLanguage : { "sSearch": "搜索:", }, fixedColumns: { leftColumns: 2, } } ); } ); </script>
在DataTable中顯示的信息默認爲英文,漢化方法java
$(document).ready(function() { $('#listtable').dataTable({ "sPaginationType" : "full_numbers", "oLanguage" : { "sLengthMenu": "每頁顯示 _MENU_ 條記錄", "sZeroRecords": "抱歉, 沒有找到", "sInfo": "從 _START_ 到 _END_ /共 _TOTAL_ 條數據", "sInfoEmpty": "沒有數據", "sInfoFiltered": "(從 _MAX_ 條數據中檢索)", "sZeroRecords": "沒有檢索到數據", "sSearch": "名稱:", "oPaginate": { "sFirst": "首頁", "sPrevious": "前一頁", "sNext": "後一頁", "sLast": "尾頁" } } } ); });