我试图让我的dataTable
在移动设备上显示友好;为此,我将dataTable
扩展为responsive
。然后它看起来很好,它自动折叠列以适应屏幕宽度。
我的表格主要由数字组成,有必要在表格的页脚显示总数。
此时,带有dataTable
扩展名的responsive
有点沮丧,因为它不会将页脚中的数据,总数,可折叠和可扩展视为表格主体。
因此,在移动设备上查看时,表页脚中的总列数将丢失。
$('table').DataTable();
body {
font-size: 140%;
}
h2 {
text-align: center;
padding: 20px 0;
}
table caption {
padding: .5em 0;
}
table.dataTable th,
table.dataTable td {
white-space: nowrap;
}
.p {
text-align: center;
padding-top: 140px;
font-size: 14px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css">
<link rel='stylesheet' href='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css'>
<link rel='stylesheet' href='https://cdn.datatables.net/plug-ins/f2c75b7247b/integration/bootstrap/3/dataTables.bootstrap.css'>
<link rel='stylesheet' href='https://cdn.datatables.net/responsive/1.0.4/css/dataTables.responsive.css'>
<div class="container">
<div class="row">
<div class="col-xs-12">
<table class="table table-bordered table-hover dt-responsive">
<thead>
<tr>
<th>Country</th>
<th>Languages</th>
<th>Population</th>
<th>Median Age</th>
<th>Area (Km²)</th>
</tr>
</thead>
<tbody>
<tr>
<td>Argentina</td>
<td>Spanish (official), English, Italian, German, French</td>
<td>41,803,125</td>
<td>31.3</td>
<td>2,780,387</td>
</tr>
<tr>
<td>Australia</td>
<td>English 79%, native and other languages</td>
<td>23,630,169</td>
<td>37.3</td>
<td>7,739,983</td>
</tr>
<tr>
<td>Greece</td>
<td>Greek 99% (official), English, French</td>
<td>11,128,404</td>
<td>43.2</td>
<td>131,956</td>
</tr>
<tr>
<td>Luxembourg</td>
<td>Luxermbourgish (national) French, German (both administrative)</td>
<td>536,761</td>
<td>39.1</td>
<td>2,586</td>
</tr>
<tr>
<td>Russia</td>
<td>Russian, others</td>
<td>142,467,651</td>
<td>38.4</td>
<td>17,076,310</td>
</tr>
<tr>
<td>Sweden</td>
<td>Swedish, small Sami- and Finnish-speaking minorities</td>
<td>9,631,261</td>
<td>41.1</td>
<td>449,954</td>
</tr>
</tbody>
<tfoot>
<tr>
<th>Total</th>
<th>6</th>
<th>229197371</th>
<th>230.4</th>
<th>28181176</th>
</tr>
</tfoot>
</table>
</div>
</div>
</div>
<script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
<script src='https://cdn.datatables.net/1.10.5/js/jquery.dataTables.min.js'></script>
<script src='https://cdn.datatables.net/plug-ins/f2c75b7247b/integration/bootstrap/3/dataTables.bootstrap.js'></script>
<script src='https://cdn.datatables.net/responsive/1.0.4/js/dataTables.responsive.js'></script>
我不会放弃确保dataTable的这种行为是否可行让表格页脚列可折叠,并且可以像表格一样扩展。我试图围绕这个主题谷歌,但没有帮助解决这个问题。
注意:文章Responsive Data Tables: A Comprehensive List of Solutions中列出了dataTable
以上的一些替代方案,这对于在小型设备上查看表格有所不同,但我的项目工作仅使用{{ 1}}。感谢。