How do I export my table with input to Excel?
How do I export my table with input to Excel?
I want to export my table to excel. Unfortunately, my table has input tag and when I tried exporting, no values from input tag are exported to excel.
My strategy is to copy the input values to the cell values. I use span to hide the cell values, so only input values are visible.
Here are my HTML.
<table id="myTable">
<thead>
<tr>
<th>Name</th>
<th>Position</th>
</tr>
</thead>
<tbody>
<tr>
<td>Tiger Nixon</td>
<td><input type="text" value="System Architect"> </td>
</tr>
<tr>
<td>Garrett Winters</td>
<td><input type="text" value="Hero"> </td>
</tr>
<tr>
<td>Ashton Cox</td>
<td><input type="text" value=""> </td>
</tr>
<tr>
<td>Donna Snider</td>
<td><span id="syncspan" style="display: none;">Hello</span><input id="syncinput" type="text" /></td>
<!-- <td><input type="text" value="Accoutnatn"> </td> -->
</tr>
</tbody>
</table>
Here are my script.
$('#myTable').DataTable(
{
dom: 'Bfrtip',
order: [],
searching: false,
columnDefs: [
{
orderable: false,
targets: [0, 1]
}],
paging: false,
buttons: [
{
extend: 'excelHtml5',
text: "Export to Excel",
}]
});
Heres how I change the span values
$('#syncspan').text("Changed test");
The thing is, the only values that got exported is the original values, Hello. Updated values never get exported.
Any advice?
Answers
Hello syaifulnizamyahya, I'm having that same case, did you find any help?
Hi @qzi35 (and @syaifulnizamyahya ),
This thread should help, it's asking the same thing.
Cheers,
Colin