Return number of discharges within a given period from remote JSON array
I have a search with from date and to date and a selectbox with departments.I want department wise discharges (count) within a given period from my remote JSON array and display in the HTML table.
This is my remote JSON array:
{
"success":true,
"dataList":[
{
"dischargedatetime":"2018-12-26T00:00:00",
"DepartmentName":"Cardiology",
"DischargeCount":3
},
{
"dischargedatetime":"2018-12-25T00:00:00",
"DepartmentName":"Cardiology",
"DischargeCount":2
},
{
"dischargedatetime":"2018-12-26T00:00:00",
"DepartmentName":"Clinical Hematology",
"DischargeCount":3
}
]
}
And this is my URL:
getDepartmentwiseDischarge?startDate=2018-12-25&endDate=2018-12-26&departmentName=Cardiology
jquery json
add a comment |
I have a search with from date and to date and a selectbox with departments.I want department wise discharges (count) within a given period from my remote JSON array and display in the HTML table.
This is my remote JSON array:
{
"success":true,
"dataList":[
{
"dischargedatetime":"2018-12-26T00:00:00",
"DepartmentName":"Cardiology",
"DischargeCount":3
},
{
"dischargedatetime":"2018-12-25T00:00:00",
"DepartmentName":"Cardiology",
"DischargeCount":2
},
{
"dischargedatetime":"2018-12-26T00:00:00",
"DepartmentName":"Clinical Hematology",
"DischargeCount":3
}
]
}
And this is my URL:
getDepartmentwiseDischarge?startDate=2018-12-25&endDate=2018-12-26&departmentName=Cardiology
jquery json
What generates your JSON data? It would be best to do the filtering based on date when querying
– Phil
Jan 2 at 4:39
add a comment |
I have a search with from date and to date and a selectbox with departments.I want department wise discharges (count) within a given period from my remote JSON array and display in the HTML table.
This is my remote JSON array:
{
"success":true,
"dataList":[
{
"dischargedatetime":"2018-12-26T00:00:00",
"DepartmentName":"Cardiology",
"DischargeCount":3
},
{
"dischargedatetime":"2018-12-25T00:00:00",
"DepartmentName":"Cardiology",
"DischargeCount":2
},
{
"dischargedatetime":"2018-12-26T00:00:00",
"DepartmentName":"Clinical Hematology",
"DischargeCount":3
}
]
}
And this is my URL:
getDepartmentwiseDischarge?startDate=2018-12-25&endDate=2018-12-26&departmentName=Cardiology
jquery json
I have a search with from date and to date and a selectbox with departments.I want department wise discharges (count) within a given period from my remote JSON array and display in the HTML table.
This is my remote JSON array:
{
"success":true,
"dataList":[
{
"dischargedatetime":"2018-12-26T00:00:00",
"DepartmentName":"Cardiology",
"DischargeCount":3
},
{
"dischargedatetime":"2018-12-25T00:00:00",
"DepartmentName":"Cardiology",
"DischargeCount":2
},
{
"dischargedatetime":"2018-12-26T00:00:00",
"DepartmentName":"Clinical Hematology",
"DischargeCount":3
}
]
}
And this is my URL:
getDepartmentwiseDischarge?startDate=2018-12-25&endDate=2018-12-26&departmentName=Cardiology
jquery json
jquery json
edited Jan 2 at 4:31
Shree
12.8k2072124
12.8k2072124
asked Jan 2 at 4:28


Rina XavierRina Xavier
11
11
What generates your JSON data? It would be best to do the filtering based on date when querying
– Phil
Jan 2 at 4:39
add a comment |
What generates your JSON data? It would be best to do the filtering based on date when querying
– Phil
Jan 2 at 4:39
What generates your JSON data? It would be best to do the filtering based on date when querying
– Phil
Jan 2 at 4:39
What generates your JSON data? It would be best to do the filtering based on date when querying
– Phil
Jan 2 at 4:39
add a comment |
1 Answer
1
active
oldest
votes
You can use forEach loop on json and bind to table like below.
var json = [{
"dischargedatetime": "2018-12-26T00:00:00",
"DepartmentName": "Cardiology",
"DischargeCount": 3
}, {
"dischargedatetime": "2018-12-25T00:00:00",
"DepartmentName": "Cardiology",
"DischargeCount": 2
}, {
"dischargedatetime": "2018-12-26T00:00:00",
"DepartmentName": "Clinical Hematology",
"DischargeCount": 3
}];
var DName = ,
DCount = ;
json.forEach(function(obj) {
if (DName.indexOf(obj.DepartmentName) == -1)
DName.push(obj.DepartmentName);
var lastIndex = DName.length - 1;
if (typeof DCount[lastIndex] == "undefined")
DCount.push(obj.DischargeCount);
else
DCount[lastIndex] += obj.DischargeCount;
});
Array.prototype.associate = function(keys) {
var result = {};
this.forEach(function(el, i) {
result[keys[i]] = el;
});
return result;
};
var datalist = DName.associate(DCount); //Make key value par after sum
var html; //Generate html for table.
$.each(datalist, function(key, val) {
html += "<tr>"
html += "<td>" + val + "</td>";
html += "<td>" + key + "</td > ";
html += "</tr>"
});
$('table').append(html);
table, th, td {
border: 1px solid black;
text-align: center;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table>
<tr>
<th>DepartmentName</th>
<th>DischargeCount</th>
</tr>
</table>
I get the feeling OP wants to total theDischargeCount
numbers perDepartmentName
(I could be wrong though)
– Phil
Jan 2 at 4:51
If op comment for that I edit my answer. Thanks for head up. @Phil
– Shree
Jan 2 at 4:52
Sir i want the total count of discharges group by month
– Rina Xavier
Jan 2 at 5:10
@RinaXavier See updated answer.
– Shree
Jan 2 at 5:48
1
Try to debug your code. It's not working is not best comment. You see working example on snippet. Any console error ?
– Shree
Jan 2 at 6:35
|
show 1 more comment
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',
autoActivateHeartbeat: false,
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54001194%2freturn-number-of-discharges-within-a-given-period-from-remote-json-array%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can use forEach loop on json and bind to table like below.
var json = [{
"dischargedatetime": "2018-12-26T00:00:00",
"DepartmentName": "Cardiology",
"DischargeCount": 3
}, {
"dischargedatetime": "2018-12-25T00:00:00",
"DepartmentName": "Cardiology",
"DischargeCount": 2
}, {
"dischargedatetime": "2018-12-26T00:00:00",
"DepartmentName": "Clinical Hematology",
"DischargeCount": 3
}];
var DName = ,
DCount = ;
json.forEach(function(obj) {
if (DName.indexOf(obj.DepartmentName) == -1)
DName.push(obj.DepartmentName);
var lastIndex = DName.length - 1;
if (typeof DCount[lastIndex] == "undefined")
DCount.push(obj.DischargeCount);
else
DCount[lastIndex] += obj.DischargeCount;
});
Array.prototype.associate = function(keys) {
var result = {};
this.forEach(function(el, i) {
result[keys[i]] = el;
});
return result;
};
var datalist = DName.associate(DCount); //Make key value par after sum
var html; //Generate html for table.
$.each(datalist, function(key, val) {
html += "<tr>"
html += "<td>" + val + "</td>";
html += "<td>" + key + "</td > ";
html += "</tr>"
});
$('table').append(html);
table, th, td {
border: 1px solid black;
text-align: center;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table>
<tr>
<th>DepartmentName</th>
<th>DischargeCount</th>
</tr>
</table>
I get the feeling OP wants to total theDischargeCount
numbers perDepartmentName
(I could be wrong though)
– Phil
Jan 2 at 4:51
If op comment for that I edit my answer. Thanks for head up. @Phil
– Shree
Jan 2 at 4:52
Sir i want the total count of discharges group by month
– Rina Xavier
Jan 2 at 5:10
@RinaXavier See updated answer.
– Shree
Jan 2 at 5:48
1
Try to debug your code. It's not working is not best comment. You see working example on snippet. Any console error ?
– Shree
Jan 2 at 6:35
|
show 1 more comment
You can use forEach loop on json and bind to table like below.
var json = [{
"dischargedatetime": "2018-12-26T00:00:00",
"DepartmentName": "Cardiology",
"DischargeCount": 3
}, {
"dischargedatetime": "2018-12-25T00:00:00",
"DepartmentName": "Cardiology",
"DischargeCount": 2
}, {
"dischargedatetime": "2018-12-26T00:00:00",
"DepartmentName": "Clinical Hematology",
"DischargeCount": 3
}];
var DName = ,
DCount = ;
json.forEach(function(obj) {
if (DName.indexOf(obj.DepartmentName) == -1)
DName.push(obj.DepartmentName);
var lastIndex = DName.length - 1;
if (typeof DCount[lastIndex] == "undefined")
DCount.push(obj.DischargeCount);
else
DCount[lastIndex] += obj.DischargeCount;
});
Array.prototype.associate = function(keys) {
var result = {};
this.forEach(function(el, i) {
result[keys[i]] = el;
});
return result;
};
var datalist = DName.associate(DCount); //Make key value par after sum
var html; //Generate html for table.
$.each(datalist, function(key, val) {
html += "<tr>"
html += "<td>" + val + "</td>";
html += "<td>" + key + "</td > ";
html += "</tr>"
});
$('table').append(html);
table, th, td {
border: 1px solid black;
text-align: center;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table>
<tr>
<th>DepartmentName</th>
<th>DischargeCount</th>
</tr>
</table>
I get the feeling OP wants to total theDischargeCount
numbers perDepartmentName
(I could be wrong though)
– Phil
Jan 2 at 4:51
If op comment for that I edit my answer. Thanks for head up. @Phil
– Shree
Jan 2 at 4:52
Sir i want the total count of discharges group by month
– Rina Xavier
Jan 2 at 5:10
@RinaXavier See updated answer.
– Shree
Jan 2 at 5:48
1
Try to debug your code. It's not working is not best comment. You see working example on snippet. Any console error ?
– Shree
Jan 2 at 6:35
|
show 1 more comment
You can use forEach loop on json and bind to table like below.
var json = [{
"dischargedatetime": "2018-12-26T00:00:00",
"DepartmentName": "Cardiology",
"DischargeCount": 3
}, {
"dischargedatetime": "2018-12-25T00:00:00",
"DepartmentName": "Cardiology",
"DischargeCount": 2
}, {
"dischargedatetime": "2018-12-26T00:00:00",
"DepartmentName": "Clinical Hematology",
"DischargeCount": 3
}];
var DName = ,
DCount = ;
json.forEach(function(obj) {
if (DName.indexOf(obj.DepartmentName) == -1)
DName.push(obj.DepartmentName);
var lastIndex = DName.length - 1;
if (typeof DCount[lastIndex] == "undefined")
DCount.push(obj.DischargeCount);
else
DCount[lastIndex] += obj.DischargeCount;
});
Array.prototype.associate = function(keys) {
var result = {};
this.forEach(function(el, i) {
result[keys[i]] = el;
});
return result;
};
var datalist = DName.associate(DCount); //Make key value par after sum
var html; //Generate html for table.
$.each(datalist, function(key, val) {
html += "<tr>"
html += "<td>" + val + "</td>";
html += "<td>" + key + "</td > ";
html += "</tr>"
});
$('table').append(html);
table, th, td {
border: 1px solid black;
text-align: center;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table>
<tr>
<th>DepartmentName</th>
<th>DischargeCount</th>
</tr>
</table>
You can use forEach loop on json and bind to table like below.
var json = [{
"dischargedatetime": "2018-12-26T00:00:00",
"DepartmentName": "Cardiology",
"DischargeCount": 3
}, {
"dischargedatetime": "2018-12-25T00:00:00",
"DepartmentName": "Cardiology",
"DischargeCount": 2
}, {
"dischargedatetime": "2018-12-26T00:00:00",
"DepartmentName": "Clinical Hematology",
"DischargeCount": 3
}];
var DName = ,
DCount = ;
json.forEach(function(obj) {
if (DName.indexOf(obj.DepartmentName) == -1)
DName.push(obj.DepartmentName);
var lastIndex = DName.length - 1;
if (typeof DCount[lastIndex] == "undefined")
DCount.push(obj.DischargeCount);
else
DCount[lastIndex] += obj.DischargeCount;
});
Array.prototype.associate = function(keys) {
var result = {};
this.forEach(function(el, i) {
result[keys[i]] = el;
});
return result;
};
var datalist = DName.associate(DCount); //Make key value par after sum
var html; //Generate html for table.
$.each(datalist, function(key, val) {
html += "<tr>"
html += "<td>" + val + "</td>";
html += "<td>" + key + "</td > ";
html += "</tr>"
});
$('table').append(html);
table, th, td {
border: 1px solid black;
text-align: center;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table>
<tr>
<th>DepartmentName</th>
<th>DischargeCount</th>
</tr>
</table>
var json = [{
"dischargedatetime": "2018-12-26T00:00:00",
"DepartmentName": "Cardiology",
"DischargeCount": 3
}, {
"dischargedatetime": "2018-12-25T00:00:00",
"DepartmentName": "Cardiology",
"DischargeCount": 2
}, {
"dischargedatetime": "2018-12-26T00:00:00",
"DepartmentName": "Clinical Hematology",
"DischargeCount": 3
}];
var DName = ,
DCount = ;
json.forEach(function(obj) {
if (DName.indexOf(obj.DepartmentName) == -1)
DName.push(obj.DepartmentName);
var lastIndex = DName.length - 1;
if (typeof DCount[lastIndex] == "undefined")
DCount.push(obj.DischargeCount);
else
DCount[lastIndex] += obj.DischargeCount;
});
Array.prototype.associate = function(keys) {
var result = {};
this.forEach(function(el, i) {
result[keys[i]] = el;
});
return result;
};
var datalist = DName.associate(DCount); //Make key value par after sum
var html; //Generate html for table.
$.each(datalist, function(key, val) {
html += "<tr>"
html += "<td>" + val + "</td>";
html += "<td>" + key + "</td > ";
html += "</tr>"
});
$('table').append(html);
table, th, td {
border: 1px solid black;
text-align: center;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table>
<tr>
<th>DepartmentName</th>
<th>DischargeCount</th>
</tr>
</table>
var json = [{
"dischargedatetime": "2018-12-26T00:00:00",
"DepartmentName": "Cardiology",
"DischargeCount": 3
}, {
"dischargedatetime": "2018-12-25T00:00:00",
"DepartmentName": "Cardiology",
"DischargeCount": 2
}, {
"dischargedatetime": "2018-12-26T00:00:00",
"DepartmentName": "Clinical Hematology",
"DischargeCount": 3
}];
var DName = ,
DCount = ;
json.forEach(function(obj) {
if (DName.indexOf(obj.DepartmentName) == -1)
DName.push(obj.DepartmentName);
var lastIndex = DName.length - 1;
if (typeof DCount[lastIndex] == "undefined")
DCount.push(obj.DischargeCount);
else
DCount[lastIndex] += obj.DischargeCount;
});
Array.prototype.associate = function(keys) {
var result = {};
this.forEach(function(el, i) {
result[keys[i]] = el;
});
return result;
};
var datalist = DName.associate(DCount); //Make key value par after sum
var html; //Generate html for table.
$.each(datalist, function(key, val) {
html += "<tr>"
html += "<td>" + val + "</td>";
html += "<td>" + key + "</td > ";
html += "</tr>"
});
$('table').append(html);
table, th, td {
border: 1px solid black;
text-align: center;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table>
<tr>
<th>DepartmentName</th>
<th>DischargeCount</th>
</tr>
</table>
edited Jan 2 at 10:49
answered Jan 2 at 4:47
ShreeShree
12.8k2072124
12.8k2072124
I get the feeling OP wants to total theDischargeCount
numbers perDepartmentName
(I could be wrong though)
– Phil
Jan 2 at 4:51
If op comment for that I edit my answer. Thanks for head up. @Phil
– Shree
Jan 2 at 4:52
Sir i want the total count of discharges group by month
– Rina Xavier
Jan 2 at 5:10
@RinaXavier See updated answer.
– Shree
Jan 2 at 5:48
1
Try to debug your code. It's not working is not best comment. You see working example on snippet. Any console error ?
– Shree
Jan 2 at 6:35
|
show 1 more comment
I get the feeling OP wants to total theDischargeCount
numbers perDepartmentName
(I could be wrong though)
– Phil
Jan 2 at 4:51
If op comment for that I edit my answer. Thanks for head up. @Phil
– Shree
Jan 2 at 4:52
Sir i want the total count of discharges group by month
– Rina Xavier
Jan 2 at 5:10
@RinaXavier See updated answer.
– Shree
Jan 2 at 5:48
1
Try to debug your code. It's not working is not best comment. You see working example on snippet. Any console error ?
– Shree
Jan 2 at 6:35
I get the feeling OP wants to total the
DischargeCount
numbers per DepartmentName
(I could be wrong though)– Phil
Jan 2 at 4:51
I get the feeling OP wants to total the
DischargeCount
numbers per DepartmentName
(I could be wrong though)– Phil
Jan 2 at 4:51
If op comment for that I edit my answer. Thanks for head up. @Phil
– Shree
Jan 2 at 4:52
If op comment for that I edit my answer. Thanks for head up. @Phil
– Shree
Jan 2 at 4:52
Sir i want the total count of discharges group by month
– Rina Xavier
Jan 2 at 5:10
Sir i want the total count of discharges group by month
– Rina Xavier
Jan 2 at 5:10
@RinaXavier See updated answer.
– Shree
Jan 2 at 5:48
@RinaXavier See updated answer.
– Shree
Jan 2 at 5:48
1
1
Try to debug your code. It's not working is not best comment. You see working example on snippet. Any console error ?
– Shree
Jan 2 at 6:35
Try to debug your code. It's not working is not best comment. You see working example on snippet. Any console error ?
– Shree
Jan 2 at 6:35
|
show 1 more comment
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54001194%2freturn-number-of-discharges-within-a-given-period-from-remote-json-array%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
What generates your JSON data? It would be best to do the filtering based on date when querying
– Phil
Jan 2 at 4:39