如何以选择性方式呈现表中的列
How to render columns in a table in a selective fashion
如何以选择性方式呈现表中的列。我有一个HTML表,其中包含默认显示的列(A、B、C、D、E)。
我希望用户根据自己的选择对其进行子过滤(例如,仅显示A、D、e)
有没有一个jQuery库可以轻松实现这种定制?
想要这样的东西吗?
$('.column').on('change', function() {
var index = $('th').index( $('th').filter('[data-column=' + $(this).data('column') + ']') );
$('th,td').filter(function() {
return $(this).index() === index;
})[ this.checked ? 'show' : 'hide' ]();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div>
<label>
<input type="checkbox" class="column" checked data-column="a" name="a"/> A
</label>
<label>
<input type="checkbox" class="column" checked data-column="b" name="b"/> B
</label>
<label>
<input type="checkbox" class="column" checked data-column="c" name="c"/> C
</label>
<label>
<input type="checkbox" class="column" checked data-column="d" name="d"/> D
</label>
<label>
<input type="checkbox" class="column" checked data-column="e" name="e"/> E
</label>
</div>
<table cellspacing="0" cellpadding="5" border="1">
<tr>
<th data-column="a">A</th>
<th data-column="b">B</th>
<th data-column="c">C</th>
<th data-column="d">D</th>
<th data-column="e">E</th>
</tr>
<tr>
<td>some data</td>
<td>some data</td>
<td>some data</td>
<td>some data</td>
<td>some data</td>
</tr>
</table>
相关文章:
- 为什么这在IE中的工作方式与在Firefox中不同
- 在AngularJS应用程序中使用封装指令和路由的推荐方式是什么
- Windows8应用程序(html&Javascript):从图片库(除了文件选择器)显示图像的另一种方式
- 在localhost Dev Box上测试JSONP请求的最佳方式
- 使用javascript存储变量的最安全方式
- 以可优化的方式使用requirejs加载模板
- 在Highcharts中,我们可以通过任何方式在渲染图表之前获得plotWidth和plotHeight
- 任何方式使AJAX调用Gmail API,而无需通过JS库
- 为react组件传递道具的最佳方式
- 让Webpack管理Quirky AMD定义的最佳方式
- 在承诺链中处理早期回报的最佳方式
- 如何“;过滤器”;或者以其他方式重构该数据
- 您有更好的动态方式来缩短复杂的代码jquery吗
- 在ng重复循环中显示条件内容的最佳方式是什么
- 在phonegap中为android调用onload函数的最佳方式
- 如何创建更好的方式来维护基于我的代码访问的最后一个页面
- Javascript以不同的方式声明数字
- 链接两个网页或网络应用程序的最佳方式
- 什么's是连接供应商js文件的最佳方式
- 如何以选择性方式呈现表中的列