By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,576 Members | 1,399 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,576 IT Pros & Developers. It's quick & easy.

How can I change column values in dynamic table

P: 2
I got from AJAX query a string like this:
Expand|Select|Wrap|Line Numbers
  1. var ansverStr = "[1,\"Bedford Street\",\"Oxford Circus, Green Park or Westminster\",\"15\",\"Regent Street\",1343329406000]\r\n
  2. [1,\"Bedford Street\",\"Oxford Circus, Green Park or Westminster\",\"13\",\"Golders Green\",1343329883000]\r\n
  3. [1,\"Bedford Street\",\"Oxford Circus, Green Park or Westminster\",\"176\",\"Tottenham Ct Rd\",1343329612000]"
... etc
Created a dynamic table to expose the data:
Expand|Select|Wrap|Line Numbers
  1. var element;
  2. element = '' + ansverStr.split('\r\n').map(function(line){ return '' + JSON.parse(line).map(function(cell){ return '' + cell + ''; }).join('') + ''; }).join('') + ''; document.getElementById("bStop").innerHTML=element;
The last field in ansverStr substrings is a time.

The question: How can I access to those values in this column in dynamic table to convert them into time format
Jul 27 '12 #1
Share this Question
Share on Google+
2 Replies


Frinavale
Expert Mod 5K+
P: 9,731
Like this:
Expand|Select|Wrap|Line Numbers
  1. var ansverStr = "[1,\"Bedford Street\",\"Oxford Circus, Green Park or Westminster\",\"15\",\"Regent Street\",1343329406000]\r\n    [1,\"Bedford Street\",\"Oxford Circus, Green Park or Westminster\",\"13\",\"Golders Green\",1343329883000]\r\n [1,\"Bedford Street\",\"Oxford Circus, Green Park or Westminster\",\"176\",\"Tottenham Ct Rd\",1343329612000]";
  2.  
  3. var lines = ansverStr.split('\r\n');
  4.  
  5. var elementContent= "";
  6.  
  7. for(lineIndex = 0; lineIndex<lines.length; lineIndex++) {
  8.     var row = JSON.parse(lines[lineIndex]);
  9.  
  10.     for (i = 0; i < row.length; i++) {
  11.         var rowData = row[i];
  12.         if (i == row.length - 1) {
  13.             var d = new Date(rowData);
  14.             elementContent = elementContent + " " + d;
  15.         } else {
  16.             elementContent = elementContent + " " + rowData;
  17.         }
  18.     }
  19.  
  20.      elementContent = elementContent + "<br /> "
  21.  
  22. }
  23.  
  24. document.getElementById("bStop").innerHTML = elementContent;
-Frinny
Jul 27 '12 #2

P: 2
Thanks, the most elegant solution :)
Jul 27 '12 #3

Post your reply

Sign in to post your reply or Sign up for a free account.