Unable to display JSON data in table form in browser











up vote
-1
down vote

favorite












Based on my generated JSON data I want to dynamically create HTML page and display data in browser. As I can see the data in my console.log but unable to display in browser.
I think my JavaScript function is not working properly e.i function CreateDetailView(objArray, theme, enableHeader)



servlet.java



GsonBuilder builder = new GsonBuilder();
builder.setPrettyPrinting();
Gson gson = builder.create();
//below line generate json data
String content = gson.toJson(metaProperties);
//here i am using servlet to set attribute for
request.setAttribute("jsonOutputContent", content);


In table.jsp file inside script tag in I am fetching the content using getAttribute() method.



table.jsp file



<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>

<head>
<title>JSON to HTML Table</title>
<script src="scripts/jquery-1.3.2.debug.js" type="text/javascript"></script>
<script src="scripts/json.htmTable.js" type="text/javascript"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="scripts/json.debug.js" type="text/javascript"></script>
<link href="styles/default.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
//here i am getting the attribute and storing in a variable
var jsonMetaDataProperties = <%= request.getAttribute("jsonOutputContent").toString() %>;
var test = eval(jsonMetaDataProperties);
alert("Test " + test.data.collection[0]["objectid"]);
var json = JSON.parse(JSON.stringify(jsonMetaDataProperties));
var arrObj = ;
arrObj = json;
//below is the methods to display json data in table
$('#DynamicGrid').append(CreateDetailView(arrObj.data.collection, "lightPro", true)).fadeIn();
</script>
</head>

<body>
<form id="form1">
<div id="DynamicGrid">
<div id="DynamicGridLoading">
<img src="image/loading.gif" /><span> Loading Data... </span>
</div>
</div>
</form>
</body>

</html>


json.htmTable.js



// This function creates a details view table with column 1 as the header and column 2 as the details
// Parameter Information
// objArray = Anytype of object array, like JSON results
// theme (optional) = A css class to add to the table (e.g. <table class="<theme>">
// enableHeader (optional) = Controls if you want to hide/show, default is show
function CreateDetailView(objArray, theme, enableHeader) {
// set optional theme parameter
if (theme === undefined) {
theme = 'mediumTable'; //default theme
}

if (enableHeader === undefined) {
enableHeader = true; //default enable headers
}

// If the returned data is an object do nothing, else try to parse
var array = typeof objArray != 'object' ? JSON.parse(objArray) : new Array(objArray);
var keys = "";
for (var a in array) {
keys = Object.keys(array[a]);
}
var str = '<table class="' + theme + '">';
str += '<tbody>';

for (var i = 0; i < array.length; i++) {
var row = 0;
for (var index in keys) {
var objValue = array[i][keys[index]]

str += (row % 2 == 0) ? '<tr class="alt">' : '<tr>';

if (enableHeader) {
str += '<th scope="row">' + keys[index] + '</th>';
}

// Support for Nested Tables
if (typeof objValue === 'object' && objValue !== null) {
if (Array.isArray(objValue)) {
str += '<td>';
for (var aindex in objValue) {
str += CreateDetailView(objValue[aindex], theme, true);
}
str += '</td>';
} else {
str += '<td>' + CreateDetailView(objValue, theme, true) + '</td>';
}
} else {
str += '<td>' + objValue + '</td>';
}

str += '</tr>';
row++;
}
}
str += '</tbody>'
str += '</table>';
return str;
}


.json file data



`{
"data": {
"type": "properties",
"metadata": ,
"objects": ,
"collection": [
{
"objectid": 1,
"name": "Model",
"properties": {
"Energy Analysis": {
"Energy Settings": ""
},
"Identity Data": {
"Author": "",
"Building Name": "",
"Organization Description": "",
"Organization Name": ""
},
"Other": {
"Client Name": "Owner",
"Project Address": "Enter address here",
"Project Issue Date": "Issue Date",
"Project Name": "Project Name",
"Project Number": "Project Number",
"Project Status": "Project Status"
}
}
},
{
"objectid": 1864,
"name": "Topography"
},
{
"objectid": 1865,
"name": "Surface [105545]",
"properties": {
"Dimensions": {
"Projected Area": "42985.637 m^2",
"Surface Area": "43753.556 m^2"
},
"Identity Data": {
"Comments": "",
"Image": "",
"Mark": "",
"Name": ""
},
"Materials and Finishes": {
"Material": "u003cBy Categoryu003e"
},
"Phasing": {
"Phase Created": "New Construction",
"Phase Demolished": "None"
}
}
},
{
"objectid": 1902,
"name": "Subregion [111931]",
"properties": {
"Dimensions": {
"Projected Area": "3676.626 m^2",
"Surface Area": "3676.632 m^2"
},
"Identity Data": {
"Comments": "",
"Image": "",
"Mark": "",
"Name": ""
},
"Materials and Finishes": {
"Material": "Site - Tarmacadam"
},
"Phasing": {
"Phase Created": "New Construction",
"Phase Demolished": "None"
}
}
},
{
"objectid": 1953,
"name": "Surface [130736]",
"properties": {
"Dimensions": {
"Projected Area": "1759.927 m^2",
"Surface Area": "1759.927 m^2"
},
"Identity Data": {
"Comments": "",
"Image": "",
"Mark": "",
"Name": ""
},
"Materials and Finishes": {
"Material": "u003cBy Categoryu003e"
},
"Phasing": {
"Phase Created": "New Construction",
"Phase Demolished": "None"
}
}
},
{
"objectid": 1954,
"name": "Pads"
},
{
"objectid": 1955,
"name": "Pad"
},
{
"objectid": 1957,
"name": "Pad 1",
"properties": {
"Analytical Properties": {
"Absorptance": "0.100",
"Heat Transfer Coefficient (U)": "0.000 watt / (m^2 kelvin)",
"Roughness": "1",
"Thermal Resistance (R)": "0.000 m^2 kelvin / watt",
"Thermal mass": "0.000 kjoule / kelvin"
},
"Construction": {
"Structure": "",
"Thickness": "300.000 mm"
},
"Graphics": {
"Coarse Scale Fill Color": "0",
"Coarse Scale Fill Pattern": ""
},
"Identity Data": {
"Assembly Code": "",
"Assembly Description": "",
"Cost": "0.000",
"Description": "",
"Keynote": "",
"Manufacturer": "",
"Model": "",
"Type Comments": "",
"Type Image": "",
"Type Mark": "",
"URL": ""
}
}
},`
etc ...


This is very big file so unable to add data....



Please helps its my first project.
Thanks in advance.










share|improve this question




















  • 1




    You've just posted a tonne of code but not actually asked a question. Try and narrow down your specific problem and post just a small piece of example code that shows what your problem is. We can help fix that small piece of code and then you can implement the fix in your own application.
    – Archer
    Nov 20 at 11:58






  • 1




    Please read "How to create a Minimal, Complete, and Verifiable example". Then use the edit link to improve your question (do not add more information via comments). Otherwise we are not able to answer your question and help you.
    – GhostCat
    Nov 20 at 12:06










  • To display data in browser we need to keep the method inside function.. $(document).ready(function() { $('#DynamicGridLoading').hide(); $('#DynamicGrid').append(CreateDetailView(test.data.collection, "lightPro", true)).fadeIn(); });
    – Hussain
    Nov 21 at 6:21












  • Thanks Sarief for understanding my problem..
    – Hussain
    Nov 21 at 6:27










  • @Sarief too much code may be a reason for downvote, read this: idownvotedbecau.se/toomuchcode @Hussain I can't see any console.log in this code, you have one alert but it shows data in test and then you pass data from json. Have you seen json's content? Have you debugged CreateDetailView function?
    – barbsan
    Nov 22 at 12:40















up vote
-1
down vote

favorite












Based on my generated JSON data I want to dynamically create HTML page and display data in browser. As I can see the data in my console.log but unable to display in browser.
I think my JavaScript function is not working properly e.i function CreateDetailView(objArray, theme, enableHeader)



servlet.java



GsonBuilder builder = new GsonBuilder();
builder.setPrettyPrinting();
Gson gson = builder.create();
//below line generate json data
String content = gson.toJson(metaProperties);
//here i am using servlet to set attribute for
request.setAttribute("jsonOutputContent", content);


In table.jsp file inside script tag in I am fetching the content using getAttribute() method.



table.jsp file



<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>

<head>
<title>JSON to HTML Table</title>
<script src="scripts/jquery-1.3.2.debug.js" type="text/javascript"></script>
<script src="scripts/json.htmTable.js" type="text/javascript"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="scripts/json.debug.js" type="text/javascript"></script>
<link href="styles/default.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
//here i am getting the attribute and storing in a variable
var jsonMetaDataProperties = <%= request.getAttribute("jsonOutputContent").toString() %>;
var test = eval(jsonMetaDataProperties);
alert("Test " + test.data.collection[0]["objectid"]);
var json = JSON.parse(JSON.stringify(jsonMetaDataProperties));
var arrObj = ;
arrObj = json;
//below is the methods to display json data in table
$('#DynamicGrid').append(CreateDetailView(arrObj.data.collection, "lightPro", true)).fadeIn();
</script>
</head>

<body>
<form id="form1">
<div id="DynamicGrid">
<div id="DynamicGridLoading">
<img src="image/loading.gif" /><span> Loading Data... </span>
</div>
</div>
</form>
</body>

</html>


json.htmTable.js



// This function creates a details view table with column 1 as the header and column 2 as the details
// Parameter Information
// objArray = Anytype of object array, like JSON results
// theme (optional) = A css class to add to the table (e.g. <table class="<theme>">
// enableHeader (optional) = Controls if you want to hide/show, default is show
function CreateDetailView(objArray, theme, enableHeader) {
// set optional theme parameter
if (theme === undefined) {
theme = 'mediumTable'; //default theme
}

if (enableHeader === undefined) {
enableHeader = true; //default enable headers
}

// If the returned data is an object do nothing, else try to parse
var array = typeof objArray != 'object' ? JSON.parse(objArray) : new Array(objArray);
var keys = "";
for (var a in array) {
keys = Object.keys(array[a]);
}
var str = '<table class="' + theme + '">';
str += '<tbody>';

for (var i = 0; i < array.length; i++) {
var row = 0;
for (var index in keys) {
var objValue = array[i][keys[index]]

str += (row % 2 == 0) ? '<tr class="alt">' : '<tr>';

if (enableHeader) {
str += '<th scope="row">' + keys[index] + '</th>';
}

// Support for Nested Tables
if (typeof objValue === 'object' && objValue !== null) {
if (Array.isArray(objValue)) {
str += '<td>';
for (var aindex in objValue) {
str += CreateDetailView(objValue[aindex], theme, true);
}
str += '</td>';
} else {
str += '<td>' + CreateDetailView(objValue, theme, true) + '</td>';
}
} else {
str += '<td>' + objValue + '</td>';
}

str += '</tr>';
row++;
}
}
str += '</tbody>'
str += '</table>';
return str;
}


.json file data



`{
"data": {
"type": "properties",
"metadata": ,
"objects": ,
"collection": [
{
"objectid": 1,
"name": "Model",
"properties": {
"Energy Analysis": {
"Energy Settings": ""
},
"Identity Data": {
"Author": "",
"Building Name": "",
"Organization Description": "",
"Organization Name": ""
},
"Other": {
"Client Name": "Owner",
"Project Address": "Enter address here",
"Project Issue Date": "Issue Date",
"Project Name": "Project Name",
"Project Number": "Project Number",
"Project Status": "Project Status"
}
}
},
{
"objectid": 1864,
"name": "Topography"
},
{
"objectid": 1865,
"name": "Surface [105545]",
"properties": {
"Dimensions": {
"Projected Area": "42985.637 m^2",
"Surface Area": "43753.556 m^2"
},
"Identity Data": {
"Comments": "",
"Image": "",
"Mark": "",
"Name": ""
},
"Materials and Finishes": {
"Material": "u003cBy Categoryu003e"
},
"Phasing": {
"Phase Created": "New Construction",
"Phase Demolished": "None"
}
}
},
{
"objectid": 1902,
"name": "Subregion [111931]",
"properties": {
"Dimensions": {
"Projected Area": "3676.626 m^2",
"Surface Area": "3676.632 m^2"
},
"Identity Data": {
"Comments": "",
"Image": "",
"Mark": "",
"Name": ""
},
"Materials and Finishes": {
"Material": "Site - Tarmacadam"
},
"Phasing": {
"Phase Created": "New Construction",
"Phase Demolished": "None"
}
}
},
{
"objectid": 1953,
"name": "Surface [130736]",
"properties": {
"Dimensions": {
"Projected Area": "1759.927 m^2",
"Surface Area": "1759.927 m^2"
},
"Identity Data": {
"Comments": "",
"Image": "",
"Mark": "",
"Name": ""
},
"Materials and Finishes": {
"Material": "u003cBy Categoryu003e"
},
"Phasing": {
"Phase Created": "New Construction",
"Phase Demolished": "None"
}
}
},
{
"objectid": 1954,
"name": "Pads"
},
{
"objectid": 1955,
"name": "Pad"
},
{
"objectid": 1957,
"name": "Pad 1",
"properties": {
"Analytical Properties": {
"Absorptance": "0.100",
"Heat Transfer Coefficient (U)": "0.000 watt / (m^2 kelvin)",
"Roughness": "1",
"Thermal Resistance (R)": "0.000 m^2 kelvin / watt",
"Thermal mass": "0.000 kjoule / kelvin"
},
"Construction": {
"Structure": "",
"Thickness": "300.000 mm"
},
"Graphics": {
"Coarse Scale Fill Color": "0",
"Coarse Scale Fill Pattern": ""
},
"Identity Data": {
"Assembly Code": "",
"Assembly Description": "",
"Cost": "0.000",
"Description": "",
"Keynote": "",
"Manufacturer": "",
"Model": "",
"Type Comments": "",
"Type Image": "",
"Type Mark": "",
"URL": ""
}
}
},`
etc ...


This is very big file so unable to add data....



Please helps its my first project.
Thanks in advance.










share|improve this question




















  • 1




    You've just posted a tonne of code but not actually asked a question. Try and narrow down your specific problem and post just a small piece of example code that shows what your problem is. We can help fix that small piece of code and then you can implement the fix in your own application.
    – Archer
    Nov 20 at 11:58






  • 1




    Please read "How to create a Minimal, Complete, and Verifiable example". Then use the edit link to improve your question (do not add more information via comments). Otherwise we are not able to answer your question and help you.
    – GhostCat
    Nov 20 at 12:06










  • To display data in browser we need to keep the method inside function.. $(document).ready(function() { $('#DynamicGridLoading').hide(); $('#DynamicGrid').append(CreateDetailView(test.data.collection, "lightPro", true)).fadeIn(); });
    – Hussain
    Nov 21 at 6:21












  • Thanks Sarief for understanding my problem..
    – Hussain
    Nov 21 at 6:27










  • @Sarief too much code may be a reason for downvote, read this: idownvotedbecau.se/toomuchcode @Hussain I can't see any console.log in this code, you have one alert but it shows data in test and then you pass data from json. Have you seen json's content? Have you debugged CreateDetailView function?
    – barbsan
    Nov 22 at 12:40













up vote
-1
down vote

favorite









up vote
-1
down vote

favorite











Based on my generated JSON data I want to dynamically create HTML page and display data in browser. As I can see the data in my console.log but unable to display in browser.
I think my JavaScript function is not working properly e.i function CreateDetailView(objArray, theme, enableHeader)



servlet.java



GsonBuilder builder = new GsonBuilder();
builder.setPrettyPrinting();
Gson gson = builder.create();
//below line generate json data
String content = gson.toJson(metaProperties);
//here i am using servlet to set attribute for
request.setAttribute("jsonOutputContent", content);


In table.jsp file inside script tag in I am fetching the content using getAttribute() method.



table.jsp file



<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>

<head>
<title>JSON to HTML Table</title>
<script src="scripts/jquery-1.3.2.debug.js" type="text/javascript"></script>
<script src="scripts/json.htmTable.js" type="text/javascript"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="scripts/json.debug.js" type="text/javascript"></script>
<link href="styles/default.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
//here i am getting the attribute and storing in a variable
var jsonMetaDataProperties = <%= request.getAttribute("jsonOutputContent").toString() %>;
var test = eval(jsonMetaDataProperties);
alert("Test " + test.data.collection[0]["objectid"]);
var json = JSON.parse(JSON.stringify(jsonMetaDataProperties));
var arrObj = ;
arrObj = json;
//below is the methods to display json data in table
$('#DynamicGrid').append(CreateDetailView(arrObj.data.collection, "lightPro", true)).fadeIn();
</script>
</head>

<body>
<form id="form1">
<div id="DynamicGrid">
<div id="DynamicGridLoading">
<img src="image/loading.gif" /><span> Loading Data... </span>
</div>
</div>
</form>
</body>

</html>


json.htmTable.js



// This function creates a details view table with column 1 as the header and column 2 as the details
// Parameter Information
// objArray = Anytype of object array, like JSON results
// theme (optional) = A css class to add to the table (e.g. <table class="<theme>">
// enableHeader (optional) = Controls if you want to hide/show, default is show
function CreateDetailView(objArray, theme, enableHeader) {
// set optional theme parameter
if (theme === undefined) {
theme = 'mediumTable'; //default theme
}

if (enableHeader === undefined) {
enableHeader = true; //default enable headers
}

// If the returned data is an object do nothing, else try to parse
var array = typeof objArray != 'object' ? JSON.parse(objArray) : new Array(objArray);
var keys = "";
for (var a in array) {
keys = Object.keys(array[a]);
}
var str = '<table class="' + theme + '">';
str += '<tbody>';

for (var i = 0; i < array.length; i++) {
var row = 0;
for (var index in keys) {
var objValue = array[i][keys[index]]

str += (row % 2 == 0) ? '<tr class="alt">' : '<tr>';

if (enableHeader) {
str += '<th scope="row">' + keys[index] + '</th>';
}

// Support for Nested Tables
if (typeof objValue === 'object' && objValue !== null) {
if (Array.isArray(objValue)) {
str += '<td>';
for (var aindex in objValue) {
str += CreateDetailView(objValue[aindex], theme, true);
}
str += '</td>';
} else {
str += '<td>' + CreateDetailView(objValue, theme, true) + '</td>';
}
} else {
str += '<td>' + objValue + '</td>';
}

str += '</tr>';
row++;
}
}
str += '</tbody>'
str += '</table>';
return str;
}


.json file data



`{
"data": {
"type": "properties",
"metadata": ,
"objects": ,
"collection": [
{
"objectid": 1,
"name": "Model",
"properties": {
"Energy Analysis": {
"Energy Settings": ""
},
"Identity Data": {
"Author": "",
"Building Name": "",
"Organization Description": "",
"Organization Name": ""
},
"Other": {
"Client Name": "Owner",
"Project Address": "Enter address here",
"Project Issue Date": "Issue Date",
"Project Name": "Project Name",
"Project Number": "Project Number",
"Project Status": "Project Status"
}
}
},
{
"objectid": 1864,
"name": "Topography"
},
{
"objectid": 1865,
"name": "Surface [105545]",
"properties": {
"Dimensions": {
"Projected Area": "42985.637 m^2",
"Surface Area": "43753.556 m^2"
},
"Identity Data": {
"Comments": "",
"Image": "",
"Mark": "",
"Name": ""
},
"Materials and Finishes": {
"Material": "u003cBy Categoryu003e"
},
"Phasing": {
"Phase Created": "New Construction",
"Phase Demolished": "None"
}
}
},
{
"objectid": 1902,
"name": "Subregion [111931]",
"properties": {
"Dimensions": {
"Projected Area": "3676.626 m^2",
"Surface Area": "3676.632 m^2"
},
"Identity Data": {
"Comments": "",
"Image": "",
"Mark": "",
"Name": ""
},
"Materials and Finishes": {
"Material": "Site - Tarmacadam"
},
"Phasing": {
"Phase Created": "New Construction",
"Phase Demolished": "None"
}
}
},
{
"objectid": 1953,
"name": "Surface [130736]",
"properties": {
"Dimensions": {
"Projected Area": "1759.927 m^2",
"Surface Area": "1759.927 m^2"
},
"Identity Data": {
"Comments": "",
"Image": "",
"Mark": "",
"Name": ""
},
"Materials and Finishes": {
"Material": "u003cBy Categoryu003e"
},
"Phasing": {
"Phase Created": "New Construction",
"Phase Demolished": "None"
}
}
},
{
"objectid": 1954,
"name": "Pads"
},
{
"objectid": 1955,
"name": "Pad"
},
{
"objectid": 1957,
"name": "Pad 1",
"properties": {
"Analytical Properties": {
"Absorptance": "0.100",
"Heat Transfer Coefficient (U)": "0.000 watt / (m^2 kelvin)",
"Roughness": "1",
"Thermal Resistance (R)": "0.000 m^2 kelvin / watt",
"Thermal mass": "0.000 kjoule / kelvin"
},
"Construction": {
"Structure": "",
"Thickness": "300.000 mm"
},
"Graphics": {
"Coarse Scale Fill Color": "0",
"Coarse Scale Fill Pattern": ""
},
"Identity Data": {
"Assembly Code": "",
"Assembly Description": "",
"Cost": "0.000",
"Description": "",
"Keynote": "",
"Manufacturer": "",
"Model": "",
"Type Comments": "",
"Type Image": "",
"Type Mark": "",
"URL": ""
}
}
},`
etc ...


This is very big file so unable to add data....



Please helps its my first project.
Thanks in advance.










share|improve this question















Based on my generated JSON data I want to dynamically create HTML page and display data in browser. As I can see the data in my console.log but unable to display in browser.
I think my JavaScript function is not working properly e.i function CreateDetailView(objArray, theme, enableHeader)



servlet.java



GsonBuilder builder = new GsonBuilder();
builder.setPrettyPrinting();
Gson gson = builder.create();
//below line generate json data
String content = gson.toJson(metaProperties);
//here i am using servlet to set attribute for
request.setAttribute("jsonOutputContent", content);


In table.jsp file inside script tag in I am fetching the content using getAttribute() method.



table.jsp file



<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>

<head>
<title>JSON to HTML Table</title>
<script src="scripts/jquery-1.3.2.debug.js" type="text/javascript"></script>
<script src="scripts/json.htmTable.js" type="text/javascript"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="scripts/json.debug.js" type="text/javascript"></script>
<link href="styles/default.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
//here i am getting the attribute and storing in a variable
var jsonMetaDataProperties = <%= request.getAttribute("jsonOutputContent").toString() %>;
var test = eval(jsonMetaDataProperties);
alert("Test " + test.data.collection[0]["objectid"]);
var json = JSON.parse(JSON.stringify(jsonMetaDataProperties));
var arrObj = ;
arrObj = json;
//below is the methods to display json data in table
$('#DynamicGrid').append(CreateDetailView(arrObj.data.collection, "lightPro", true)).fadeIn();
</script>
</head>

<body>
<form id="form1">
<div id="DynamicGrid">
<div id="DynamicGridLoading">
<img src="image/loading.gif" /><span> Loading Data... </span>
</div>
</div>
</form>
</body>

</html>


json.htmTable.js



// This function creates a details view table with column 1 as the header and column 2 as the details
// Parameter Information
// objArray = Anytype of object array, like JSON results
// theme (optional) = A css class to add to the table (e.g. <table class="<theme>">
// enableHeader (optional) = Controls if you want to hide/show, default is show
function CreateDetailView(objArray, theme, enableHeader) {
// set optional theme parameter
if (theme === undefined) {
theme = 'mediumTable'; //default theme
}

if (enableHeader === undefined) {
enableHeader = true; //default enable headers
}

// If the returned data is an object do nothing, else try to parse
var array = typeof objArray != 'object' ? JSON.parse(objArray) : new Array(objArray);
var keys = "";
for (var a in array) {
keys = Object.keys(array[a]);
}
var str = '<table class="' + theme + '">';
str += '<tbody>';

for (var i = 0; i < array.length; i++) {
var row = 0;
for (var index in keys) {
var objValue = array[i][keys[index]]

str += (row % 2 == 0) ? '<tr class="alt">' : '<tr>';

if (enableHeader) {
str += '<th scope="row">' + keys[index] + '</th>';
}

// Support for Nested Tables
if (typeof objValue === 'object' && objValue !== null) {
if (Array.isArray(objValue)) {
str += '<td>';
for (var aindex in objValue) {
str += CreateDetailView(objValue[aindex], theme, true);
}
str += '</td>';
} else {
str += '<td>' + CreateDetailView(objValue, theme, true) + '</td>';
}
} else {
str += '<td>' + objValue + '</td>';
}

str += '</tr>';
row++;
}
}
str += '</tbody>'
str += '</table>';
return str;
}


.json file data



`{
"data": {
"type": "properties",
"metadata": ,
"objects": ,
"collection": [
{
"objectid": 1,
"name": "Model",
"properties": {
"Energy Analysis": {
"Energy Settings": ""
},
"Identity Data": {
"Author": "",
"Building Name": "",
"Organization Description": "",
"Organization Name": ""
},
"Other": {
"Client Name": "Owner",
"Project Address": "Enter address here",
"Project Issue Date": "Issue Date",
"Project Name": "Project Name",
"Project Number": "Project Number",
"Project Status": "Project Status"
}
}
},
{
"objectid": 1864,
"name": "Topography"
},
{
"objectid": 1865,
"name": "Surface [105545]",
"properties": {
"Dimensions": {
"Projected Area": "42985.637 m^2",
"Surface Area": "43753.556 m^2"
},
"Identity Data": {
"Comments": "",
"Image": "",
"Mark": "",
"Name": ""
},
"Materials and Finishes": {
"Material": "u003cBy Categoryu003e"
},
"Phasing": {
"Phase Created": "New Construction",
"Phase Demolished": "None"
}
}
},
{
"objectid": 1902,
"name": "Subregion [111931]",
"properties": {
"Dimensions": {
"Projected Area": "3676.626 m^2",
"Surface Area": "3676.632 m^2"
},
"Identity Data": {
"Comments": "",
"Image": "",
"Mark": "",
"Name": ""
},
"Materials and Finishes": {
"Material": "Site - Tarmacadam"
},
"Phasing": {
"Phase Created": "New Construction",
"Phase Demolished": "None"
}
}
},
{
"objectid": 1953,
"name": "Surface [130736]",
"properties": {
"Dimensions": {
"Projected Area": "1759.927 m^2",
"Surface Area": "1759.927 m^2"
},
"Identity Data": {
"Comments": "",
"Image": "",
"Mark": "",
"Name": ""
},
"Materials and Finishes": {
"Material": "u003cBy Categoryu003e"
},
"Phasing": {
"Phase Created": "New Construction",
"Phase Demolished": "None"
}
}
},
{
"objectid": 1954,
"name": "Pads"
},
{
"objectid": 1955,
"name": "Pad"
},
{
"objectid": 1957,
"name": "Pad 1",
"properties": {
"Analytical Properties": {
"Absorptance": "0.100",
"Heat Transfer Coefficient (U)": "0.000 watt / (m^2 kelvin)",
"Roughness": "1",
"Thermal Resistance (R)": "0.000 m^2 kelvin / watt",
"Thermal mass": "0.000 kjoule / kelvin"
},
"Construction": {
"Structure": "",
"Thickness": "300.000 mm"
},
"Graphics": {
"Coarse Scale Fill Color": "0",
"Coarse Scale Fill Pattern": ""
},
"Identity Data": {
"Assembly Code": "",
"Assembly Description": "",
"Cost": "0.000",
"Description": "",
"Keynote": "",
"Manufacturer": "",
"Model": "",
"Type Comments": "",
"Type Image": "",
"Type Mark": "",
"URL": ""
}
}
},`
etc ...


This is very big file so unable to add data....



Please helps its my first project.
Thanks in advance.







javascript java json jsp






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 22 at 12:52









barbsan

2,1481022




2,1481022










asked Nov 20 at 11:54









Hussain

61




61








  • 1




    You've just posted a tonne of code but not actually asked a question. Try and narrow down your specific problem and post just a small piece of example code that shows what your problem is. We can help fix that small piece of code and then you can implement the fix in your own application.
    – Archer
    Nov 20 at 11:58






  • 1




    Please read "How to create a Minimal, Complete, and Verifiable example". Then use the edit link to improve your question (do not add more information via comments). Otherwise we are not able to answer your question and help you.
    – GhostCat
    Nov 20 at 12:06










  • To display data in browser we need to keep the method inside function.. $(document).ready(function() { $('#DynamicGridLoading').hide(); $('#DynamicGrid').append(CreateDetailView(test.data.collection, "lightPro", true)).fadeIn(); });
    – Hussain
    Nov 21 at 6:21












  • Thanks Sarief for understanding my problem..
    – Hussain
    Nov 21 at 6:27










  • @Sarief too much code may be a reason for downvote, read this: idownvotedbecau.se/toomuchcode @Hussain I can't see any console.log in this code, you have one alert but it shows data in test and then you pass data from json. Have you seen json's content? Have you debugged CreateDetailView function?
    – barbsan
    Nov 22 at 12:40














  • 1




    You've just posted a tonne of code but not actually asked a question. Try and narrow down your specific problem and post just a small piece of example code that shows what your problem is. We can help fix that small piece of code and then you can implement the fix in your own application.
    – Archer
    Nov 20 at 11:58






  • 1




    Please read "How to create a Minimal, Complete, and Verifiable example". Then use the edit link to improve your question (do not add more information via comments). Otherwise we are not able to answer your question and help you.
    – GhostCat
    Nov 20 at 12:06










  • To display data in browser we need to keep the method inside function.. $(document).ready(function() { $('#DynamicGridLoading').hide(); $('#DynamicGrid').append(CreateDetailView(test.data.collection, "lightPro", true)).fadeIn(); });
    – Hussain
    Nov 21 at 6:21












  • Thanks Sarief for understanding my problem..
    – Hussain
    Nov 21 at 6:27










  • @Sarief too much code may be a reason for downvote, read this: idownvotedbecau.se/toomuchcode @Hussain I can't see any console.log in this code, you have one alert but it shows data in test and then you pass data from json. Have you seen json's content? Have you debugged CreateDetailView function?
    – barbsan
    Nov 22 at 12:40








1




1




You've just posted a tonne of code but not actually asked a question. Try and narrow down your specific problem and post just a small piece of example code that shows what your problem is. We can help fix that small piece of code and then you can implement the fix in your own application.
– Archer
Nov 20 at 11:58




You've just posted a tonne of code but not actually asked a question. Try and narrow down your specific problem and post just a small piece of example code that shows what your problem is. We can help fix that small piece of code and then you can implement the fix in your own application.
– Archer
Nov 20 at 11:58




1




1




Please read "How to create a Minimal, Complete, and Verifiable example". Then use the edit link to improve your question (do not add more information via comments). Otherwise we are not able to answer your question and help you.
– GhostCat
Nov 20 at 12:06




Please read "How to create a Minimal, Complete, and Verifiable example". Then use the edit link to improve your question (do not add more information via comments). Otherwise we are not able to answer your question and help you.
– GhostCat
Nov 20 at 12:06












To display data in browser we need to keep the method inside function.. $(document).ready(function() { $('#DynamicGridLoading').hide(); $('#DynamicGrid').append(CreateDetailView(test.data.collection, "lightPro", true)).fadeIn(); });
– Hussain
Nov 21 at 6:21






To display data in browser we need to keep the method inside function.. $(document).ready(function() { $('#DynamicGridLoading').hide(); $('#DynamicGrid').append(CreateDetailView(test.data.collection, "lightPro", true)).fadeIn(); });
– Hussain
Nov 21 at 6:21














Thanks Sarief for understanding my problem..
– Hussain
Nov 21 at 6:27




Thanks Sarief for understanding my problem..
– Hussain
Nov 21 at 6:27












@Sarief too much code may be a reason for downvote, read this: idownvotedbecau.se/toomuchcode @Hussain I can't see any console.log in this code, you have one alert but it shows data in test and then you pass data from json. Have you seen json's content? Have you debugged CreateDetailView function?
– barbsan
Nov 22 at 12:40




@Sarief too much code may be a reason for downvote, read this: idownvotedbecau.se/toomuchcode @Hussain I can't see any console.log in this code, you have one alert but it shows data in test and then you pass data from json. Have you seen json's content? Have you debugged CreateDetailView function?
– barbsan
Nov 22 at 12:40

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53392455%2funable-to-display-json-data-in-table-form-in-browser%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53392455%2funable-to-display-json-data-in-table-form-in-browser%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

What visual should I use to simply compare current year value vs last year in Power BI desktop

Alexandru Averescu

Trompette piccolo