I am running into a problem here. I parse a .CSV file and I need to show them into a DataTables format.
The problem is The markups are all inside javascript as shown below
$("#upload").bind("click", function () {
var regex = /^([a-zA-Z0-9\s_\\.\-:])+(.csv|.xlsx|.xls)$/;
if (regex.test($("#fileUpload").val().toLowerCase())) {
if (typeof (FileReader) != "undefined") {
var reader = new FileReader();
reader.onload = function (e) {
var table = $("<table id='comp-monitor' class='table table-condensed table-striped'> \n\
<tr><th>No.</th><th>DESKRIPSI ASSEMBLY</th><th>Drawing No.</th><th>QTY3</th><th>WEIGHT</th><th>-</th></tr>");
var rows = e.target.result.split("\n");
var no = 0;
for (var i = 0; i < rows.length; i++) {
no++;
// console.log(i);
var row = $("<tr />");
var cells = rows[i].split(",");
// Column No
var cell_no = $("<td />");
cell_no.html(no);
row.append(cell_no);
for (var j = 0; j < cells.length; j++) {
var cell = $("<td />");
cell.html(cells[j]);
row.append(cell);
}
table.append(row);
}
$("#dvCSV").html('');
$("#dvCSV").append(table);
}
reader.readAsText($("#fileUpload")[0].files[0]);
} else {
alert("This browser does not support HTML5.");
}
} else {
alert("Please upload a valid CSV file.");
}
});
and the jquery initialization is just outside that function
$('#comp-monitor').DataTable();
Somehow the datatables doesn't run and I need some help with this where to put the initialization.
Thanks a bunch,