SOLUTION
You can use $() method to get access to all rows even not present in DOM and construct a new table using these rows. Then you can execute table2excel() on a newly constructed table to get Excel file that contains all rows.
For example:
$(function() {
var startDate = $(".startDate").val();
var endDate = $(".endDate").val();
$("#exportExcel").click(function(){
$('<table>')
.append(
$("#table_id").DataTable().$('tr').clone()
)
.table2excel({
exclude: ".excludeThisClass",
name: "Worksheet Name",
filename: "SomeFile" //do not include extension
});
});
$("#table_id").dataTable();
});
DEMO
See this page for code and demonstration.
NOTES
Excel 2013 displays the following error when opening the file produced by table2excel.js.
Excel cannot open the file
[filename]because the file format or file extension is not valid. Verify that the file has not been corrupted and that the file extension matches the format of the file.
Because of this error, I would rather use DataTables TableTools plug-in instead even though it can only produce CSV files and also uses Flash.
Answer from Gyrocode.com on Stack OverflowSOLUTION
You can use $() method to get access to all rows even not present in DOM and construct a new table using these rows. Then you can execute table2excel() on a newly constructed table to get Excel file that contains all rows.
For example:
$(function() {
var startDate = $(".startDate").val();
var endDate = $(".endDate").val();
$("#exportExcel").click(function(){
$('<table>')
.append(
$("#table_id").DataTable().$('tr').clone()
)
.table2excel({
exclude: ".excludeThisClass",
name: "Worksheet Name",
filename: "SomeFile" //do not include extension
});
});
$("#table_id").dataTable();
});
DEMO
See this page for code and demonstration.
NOTES
Excel 2013 displays the following error when opening the file produced by table2excel.js.
Excel cannot open the file
[filename]because the file format or file extension is not valid. Verify that the file has not been corrupted and that the file extension matches the format of the file.
Because of this error, I would rather use DataTables TableTools plug-in instead even though it can only produce CSV files and also uses Flash.
I find the solution here to export data from the table to excel sheet