当用户点击 thead 中的一个单元格时,我会使用一个输入元素和一个过滤器图标来填充它。问题是它使列的宽度跳跃:
<table class="table">
<thead>
<tr>
<th>One</th>
<th>Two</th>
</tr>
<tr>
<th class='clickhere'>Click here
</th>
<th class='clickhere'>or here</th>
</tr>
</thead>
<tbody>
<tr>
<td>11</td>
<td>21</td>
</tr>
<tr>
<td>12</td>
<td>22</td>
</tr>
</tbody>
<table>
$(document).on('blur','.clickhere input',filterBlurred);
function filterBlurred() {
if ($(this).val() === '') {
$(this).closest('tr').find('th').html(' ');
}
}
$(document).on('click','.clickhere',filter);
function filter() {
$(this).html('<div class="input-group"><input class="form-control"><span class="btn input-group-addon glyphicon glyphicon-filter"> </span></div>');
$(this).find('input').focus();
}