Create table from JSON - jQuery

by lshettyl

JavaScript

var data = [{"CategoryName":"Flash News","DisplayOrder":"0","ENoticeDescription":"","ENoticeId":19619,"NoticeDocument":"","Subject":"Singing competitions will be conducted this Month, interested candidates can come to office room and enroll.","createddate":"12 Jun 2014","noticedate":"6\/12\/2014 12:00:00 AM"},{"CategoryName":"Flash News","DisplayOrder":"0","ENoticeDescription":"","ENoticeId":19623,"NoticeDocument":"","Subject":"Flowers day celebrations will be conducted on 1st Saturday of next Month, Students are instructed to bring 5 different Flowers.","createddate":"12 Jun 2014","noticedate":"6\/12\/2014 12:00:00 AM"},{"CategoryName":"Flash News","DisplayOrder":"0","ENoticeDescription":"","ENoticeId":19624,"NoticeDocument":"","Subject":"Painting competitions for Senior Program will be conducted on 30th of this month.","createddate":"12 Jun 2014","noticedate":"6\/12\/2014 12:00:00 AM"},{"CategoryName":"Flash News","DisplayOrder":"0","ENoticeDescription":"Debate competition for Senior class students will be conducted on 2nd of April month, interested students contact Head of Senior Program Staff.","ENoticeId":19660,"NoticeDocument":"","Subject":"Senior Program - Debate Competition","createddate":"12 Jun 2014","noticedate":"6\/12\/2014 12:00:00 AM"}];

var $table = $('<table width="400" height="288" align="center"  style="border:5px solid #10A3D8;">');
var $trs = $();
$.each(data, function() {
    var $tr = $("<tr/>").css("background", "#D4D2D2");
    var $td = $("<td/>").css("color", "#041DB3").text("Subject:");
    $tr.append($td);
    $td = $("<td/>").css("color", "#041DB3").text(this.Subject);
    $tr.append($td);
    $trs = $trs.add($tr);
    
    $tr = $("<tr/>").css("background", "#04A273");
    $td = $("<td/>").css("color", "#041DB3").text("Description:");
    $tr.append($td);
    $td = $("<td/>").css("color", "#041DB3").text(this.ENoticeDescription);
    $tr.append($td);
    $trs =...