0

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

1 Answer 1

1

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 );
Sign up to request clarification or add additional context in comments.

2 Comments

THANK YOU FOR THAT ONE. It is working now but the table is Duplicating the array object and displays each item 33 time?
If you an update your question with an example of what the data actually looks like I might be able to help you better.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.