【发布时间】:2014-02-09 23:18:59
【问题描述】:
我有一些表格与这个插件https://github.com/btechco/btechco_excelexport 结合将数据导出到excel。然后我用复选框控制表格以显示或隐藏表格的特定列。
但是,我如何才能导出到只有可见 tr 表的 excel?
表格。
<div>
<input type="checkbox" value="blabla" checked="checked">Column 1
<input type="checkbox" value="blabla" checked="checked">Column 2
<input type="checkbox" value="blabla" checked="checked">Column 3
</div>
<button id="btnExport">Export</button>
<table id="tableexport">
<thead>
<tr>
<th>No.</th>
<th>Name</th>
<th>Phone</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>John</td>
<td>123456</td>
</tr>
<tr>
<td>2</td>
<td>Anne</td>
<td>987654</td>
</tr>
<tr>
<td>3</td>
<td>Nikki</td>
<td>786578</td>
</tr>
</tbody>
<table>
隐藏和显示 tr 表
$(document).on('change', 'div input', function() {
var checked = $(this).is(":checked");
var index = $(this).parent().index();
$('table thead tr ').each(function() {
if(checked) {
$(this).find("th").eq(index).show();
} else {
$(this).find("th").eq(index).hide();
}
});
$('table tbody tr ').each(function() {
if(checked) {
$(this).find("td").eq(index).show();
} else {
$(this).find("td").eq(index).hide();
}
});
});
这个代码将表格导出到excel。 (插件)
$(document).ready(function() {
$("#btnExport").click(function () {
$("#tableexport").btechco_excelexport({
containerid: "tableexport"
, datatype: $datatype.Table
});
});
});
【问题讨论】:
-
导出时,您可以通过表运行,检查其可见性并将可见内容写入对象并将其发送到您的函数。