Hi,
I have a simple json which I am trying to parse and push it to data table.
Here's the json.
[{"Practice Name":"SOUTHWEST INTEGRATIVE HEALTH CENTER, LLC","Address":"SOUTHWEST INTEGRATIVE HEALTH CENTER LLC","For individual":"Exempt from MIPS. This clinician has billed Medicare for $30,000 or less and has provided care for 100 or fewer patients at this practice.","For group":"Included in MIPS. This practice has billed Medicare for more than $30,000 and has provided care for more than 100 patients."}]
I tried with the examples in the forum but somehow I am not able to get this to the table.
And here's my JS.
function Getdet(Name) {
$.ajax({
type: "POST",
url: "GetDetailsService.asmx/MIPSCAL",
data: "{'NPI':'" + Name + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
$("#spnGetdet").html(response.d);
//CreateTableFromJSON(response.d);
$('#gvJsonData').html(CreateTableView(response.d));
},
failure: function (msg) {
alert(msg);
}
});
}
function CreateTableView(objArray, theme, enableHeader) {
// set optional theme parameter
if (theme === undefined) {
theme = 'lightPro'; //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 = Object.keys(array[0]);
alert(array);
var str = '<table class="' + theme + '">';
// table head
if (enableHeader) {
str += '<thead><tr>';
for (var index in keys) {
str += '<th scope="col">' + keys[index] + '</th>';
}
str += '</tr></thead>';
}
// table body
str += '<tbody>';
for (var i = 0; i < array.length; i++) {
str += (i % 2 == 0) ? '<tr class="alt">' : '<tr>';
for (var index in keys) {
var objValue = array[i][keys[index]];
// Support for Nested Tables
if (typeof objValue === 'object' && objValue !== null) {
if (Array.isArray(objValue)) {
str += '<td>';
for (var aindex in objValue) {
str += CreateTableView(objValue[aindex], theme, true);
}
str += '</td>';
} else {
str += '<td>' + CreateTableView(objValue, theme, true) + '</td>';
}
} else {
str += '<td>' + objValue + '</td>';
}
}
str += '</tr>';
}
str += '</tbody>'
str += '</table>';
return str;
}
<div id="gvJsonData"></div>
What am I missing here? I don't see the table in the output.