I am not sure this is complex to be solve but it is related between Problem 1 and 2. I have no idea to solve this at this moment. I am stuck here for 4 days. :-(
- I have thousand entries to be export to excel.
- I have
<table>tag which will have multiple rows inside each datatable row. - I need to export all the datatable rows (including
<table>rows). - I try to use build-in export function but the result is not as requested (it become straight line), so I need to create another function (exportNotFound) which will fetch all datatable rows to be export in excel.
Some References:
- https://datatables.net/examples/api/counter_columns.html (Not working as expected)
- Add row number column to jquery datatables (Tried but after export got white blank excel)
At last I just do as simple as below to have a numbering for each row, however the numbering is not sorting properly. At console the numbering is sorting properly.
Problem:
- How to sort the number properly?
- Why the current page (by default show 10 items) become blank and the page load too many rows instead of 10 items after trigger
exportNotFoundfunction?
Console
Current result table after export. Sorting number is not properly.
Blank items dropdown after trigger exportNotFound function.
Suddenly it load additional multiple rows after trigger exportNotFound function.
<table id="table2">
<thead>
<tr>
<th>Not Found in Grand</th>
</tr>
</thead>
</table>
JS
var result2 = [];
var count2 = 1;
$.each(response.not_found, function(k1, v1) {
if (v1.router != null){
var obj = {};
obj['result_not_found'] = v1.router;
obj['count2'] = count2++;
result2.push(obj);
}
});
resultTable2(result2);
function resultTable2(result2){
$('#table2').DataTable({
buttons: [{
action: function () {
exportNotFound();
},
}],
columns: [
{
"data": "result_not_found",
render: function(data, type, row) {
var a = "<table>";
a += "<tr><td><span>("+row.count2+")</span>SERVICE NO:</td><td>"+data.service_number+"</td></tr>";
a += "<tr><td>MSE ID:</td><td>"+data.mse_id+"</td></tr>";
a += "<tr><td>MSE INTERFACE:</td><td>"+data.mse_interface+"</td></tr>";
a += "<tr><td>VLAN:</td><td>"+data.vlan+"</td></tr>";
a += "<tr><td>BANDWIDTH:</td><td>"+data.bandwidth+"</td></tr>";
return a + "</table></br>";
}
}
],
});
}
function exportNotFound() {
var BOM = "\uFEFF";
var table = $('#table2').DataTable();
var pages = table.page.info().pages;
table.page.len(-1).draw();
var html = $("#table2")[0].outerHTML;
table.page.len(pages).draw();
window.open('data:application/vnd.ms-excel,' + encodeURI(BOM + html));
}



