Click here to Skip to main content
15,896,526 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to display the data in table format using javascript...data is read from the xml file and here in the below code wat i mentioned.... instead of displaying the message as it is i need to display the coresponding field data in the format of table.
I have some six fields like name,last,open,low ,high,chrg...
Help me out in doing this...

XML
function broadcastListener(msg) {
for(int i=0;i<1000;i++)
{
  console.log("received broadcast: " + msg + ", " + msg.data[i]);
  $(<'<tr>')
  $('<td>').html(msg.data[i]).prependTo('#contentList').animate({color: "#000000"}, 6000);
  $('<tr>')
  }
  $('html, body').animate({ scrollTop: 0 }, 0);
}


google.load("jquery", "1");

/**
* Callback function - Cometd consumer.
*/
google.setOnLoadCallback(function() {
$.getScript("http://jquerycomet.googlecode.com/svn/trunk/jquery.comet.js", function(){
console.log("done loading js");
$.comet.init("http://localhost:9099/cometd");
$.comet.subscribe("/broadcastMessageChannel", broadcastListener);
});

});

/**
* Listener function called on receipt of broadcast message.
*/
function broadcastListener(msg) {
for(int i=0;i<1000;i++)
{
console.log("received broadcast: " + msg + ", " + msg.data[i]);
$(<'')
$('').html(msg.data[i]).prependTo('#contentList').animate({color: "#000000"}, 6000);
$('')

$('html, body').animate({ scrollTop: 0 }, 0);
}
}

this is the code wat i have....the below mentioned solutions are not giving outcome for me... f i could not understand wat is controlid and for wat v r using it plz xplain



Thank u
Priyanka
Posted
Updated 12-May-19 18:24pm
v2

Hi Priyanka,

try the following code.
JavaScript
 var table  =  '<table>';

for(int i=0;i<1000;i++)
{
	console.log("received broadcast: " + msg + ", " + msg.data[i]);
	table += '<tr>'
	table += '<td>'
	table += msg.data[i];
	table += '</td>'
	table += '</tr>'
}

table  += '</table>';

$('controlid').html(table);


You can add anything to table dynamically like class, additional attribute or control by this.
Hope this helps!
 
Share this answer
 
i usually use the append..

JavaScript
var $table  =  $('<table></table>');

for(int i=0;i<1000;i++)
{
    console.log("received broadcast: " + msg + ", " + msg.data[i]);
    var $tr =  $('<tr></tr>');
    var $td =  $('<td></td>');
    $td.append(msg.data[i]);
    $tr.append($td);
    $table.append($tr);
}

$('div#target').empty().append($table);


this will fill the table inside the element
JavaScript
<div id="target"></div>
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900