DataTables+BootStrap制作一个小字体的html的表格,分页,排序等
时间: 2024-02-25 17:52:48 浏览: 65
datatables表格分页、检索、排序、滚动条
可以使用DataTables和Bootstrap来制作一个小字体的HTML表格,同时添加分页和排序功能。下面是一个示例代码,你可以根据自己的需求进行修改:
```html
<!DOCTYPE html>
<html>
<head>
<title>DataTables + Bootstrap Example</title>
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.22/css/dataTables.bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
</head>
<body>
<div class="container">
<h1>DataTable Example</h1>
<table id="example" class="table table-striped table-bordered" style="width:100%">
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Age</th>
<th>Gender</th>
<th>Address</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>John</td>
<td>25</td>
<td>Male</td>
<td>123 Main St, New York, NY</td>
</tr>
<tr>
<td>2</td>
<td>Jane</td>
<td>30</td>
<td>Female</td>
<td>456 Elm St, San Francisco, CA</td>
</tr>
<tr>
<td>3</td>
<td>Bob</td>
<td>45</td>
<td>Male</td>
<td>789 Oak Ave, Los Angeles, CA</td>
</tr>
<tr>
<td>4</td>
<td>Alice</td>
<td>22</td>
<td>Female</td>
<td>321 Maple St, Chicago, IL</td>
</tr>
<tr>
<td>5</td>
<td>Mike</td>
<td>35</td>
<td>Male</td>
<td>654 Pine St, Boston, MA</td>
</tr>
</tbody>
</table>
</div>
<script type="text/javascript" src="https://code.jquery.com/jquery-3.5.1.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/1.10.22/js/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/1.10.22/js/dataTables.bootstrap.min.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/plug-ins/1.10.22/pagination/simple_numbers_no_ellipses.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#example').DataTable({
"pagingType": "simple_numbers_no_ellipses",
"lengthMenu": [ 5, 10, 25, 50 ],
"pageLength": 5,
"order": [[ 0, "asc" ]]
});
});
</script>
</body>
</html>
```
在这个示例中,我们使用了DataTables和Bootstrap的样式和JS文件。表格中包含了一些数据,并且设置了分页和排序功能。你可以自己修改表格的数据和样式。
阅读全文