Reputation: 45
Im trying to do something similar to this answer: How to add multiple rows to a jQuery DataTable from a html string
The only difference is: I need to add multiple values that i will get from a text area. The first part works perfectly.
function Gen(){
var data = require('../../cases/config.json');
var tableHeaders;
var cantidad = 0;
$.each(data.Ge[0].Data, function(i, val){
cantidad += 1
tableHeaders += "<th>" + val + "</th>";
});
// Header
$("#tabGen").empty();
$("#tabGen").append('<thead><tr>' + tableHeaders + '</tr></thead>');
var t = $('#tabGen').DataTable({
"scrollY": 200,
"scrollX": true,
rowReorder: true,
autoFill: true,
select:true,
stateSave: true
});
This second part when doing the t.row.add($(info)).draw(); it doesn't appear all the data that i need to show. So when I check out the other answer I saw that I can add a single row from an html string. So I don't know how can I add multiple values inside of the table.
$('#excel').on( 'click', function () {
var inf = $('textarea[name=excel_data]').val();
var rows = inf.split("\n");
for(var y = 0; y < rows.length; y++) {
var cells = rows[y].split("\t");
for(var x in cells) {
var info = '<td><input type="text" id="inputTextAg'+x+'" name="inputTextAg'+x+'" value="'+cells[x]+'" draggable="true" "></td>'
t.rows.add($(info)).draw();
}
}
});
}
Thanks!
Upvotes: 0
Views: 431
Reputation: 2667
Try this:
$('#excel').on( 'click', function () {
var inf = $('textarea[name=excel_data]').val();
var rows = inf.split("\n");
for(var y = 0; y < rows.length; y++) {
var cells = rows[y].split("\t");
var info = '<tr>';
for(var x in cells) {
info += '<td><input type="text" id="inputTextAg'+x+'" name="inputTextAg'+x+'" value="'+cells[x]+'" draggable="true" "></td>';
}
info += '</tr>';
t.rows.add($(info)).draw();
}
});
}
Upvotes: 1