Reputation: 3
I am busy with an HTML
page that I have sent through data from a database
. I have the array working and I am filtering correctly, then I used a for loop to get the object in an el
function. the console log's correctly, but the table on the page where I would like to display does a letter on a line.
JAVASCRIPT
function go(){
var startd = document.getElementById('startdate').value+" 00:00";
var stopd = document.getElementById('stopdate').value;
var array = [<%items.forEach(function(item, index){%>{date:"<%= item.Expr1000%>", inout:"<%= item.CHECKTYPE%>", sn:"<%= item.sn%>"},<% });%>{date:"stop"}];
var check = array.filter(function(el){
return el.date >= startd &&
el.date <= stopd &&
el.inout &&
el.sn;
});
check.forEach(function(el){
console.log(el.date);
var table = $('#set');
var row, cell;
for(var i=0; i<el.date.length; i++){
row = $( '<tr />' );
table.append( row );
for(var j=0; j<el.date[i].length; j++){
cell = $('<td>'+el.date[i][j]+'</td>');
row.append( cell );
}
}
});
}
Currently displays the date like:
2
0
1
9
-
0
8
-
1
5
0
7
:
0
0
:
2
1
2
0
1
9
-
0
8
-
1
5
0
7
:
0
0
:
3
0
Where I would like to display as:
yyyy-mm-dd hh:mm:ss
yyyy-mm-dd hh:mm:ss
Upvotes: 0
Views: 99
Reputation: 3443
Your second loop is the problem:
for(var j=0; j<el.date[i].length; j++){
cell = $('<td>'+el.date[i][j]+'</td>');
row.append( cell );
}
That is looping over every character in the date. You don't need the second loop at all—just add the date directly to the row
:
cell = $('<td>'+el.date[i]+'</td>');
row.append( cell );
Upvotes: 1