Populate Custom Caption from Json - json

How can i populate caption of the table with the hospitallName & Date supplied in the json data?
** expected output is added here **
Json :
{
"sEcho":2,
"iTotalRecords":243,
"iTotalDisplayRecords":243,
"aaData":[
[
"Mark Zuckerberg",
"USA",
"Feb 14, 1943"
],
[
"John Mathew",
"UK",
"Feb 14, 1943"
],
[
"John Mathew",
"USA",
"Feb 14, 1943"
]
],
"Date":"Aug 01, 2016 - Aug 05, 2016",
"hospitallName":"Apollo Hospital Center"
}
--
on my server side,i am calling like this,
$(document).ready(function() {
oTable = $('#report').dataTable({
"bJQueryUI": true,
"sPaginationType": "full_numbers",
"bServerSide": true,
"bProcessing":true,
"bFilter":true,
"oLanguage": {
"sProcessing": "Please wait..."
},
"sAjaxSource": "myDataTableAction.action",
"aaSorting": [],
});
$('td.options span').hide();
$('<caption/>').html('<h2 style="text-align: center;background-color:#f9b660 !important ; line-height: 45px;">Have to show hosital Name & Date here</h2>').appendTo( '#report' );
});

You can use ajax instead of sAjaxSource and use the dataSrc callback to populate the headers. You are not giving any example of layout or markup, but if you give the relevant headers an id you can do the following :
ajax: {
url: 'myDataTableAction.action',
dataSrc: function(json) {
$('#date_head').text(json.Date)
$('#hospitalName_head').text(json.hospitallName)
return json.aaData
}
}
see demo -> http://jsfiddle.net/zvqdpeky/

Related

fullcalendar won't display json feed using eventSource

I'm working with fullcalendar for the first time. it seemed straight forward at first but then problems. Ok I am trying to use eventSource to load multiple sources. It loads all the google calendar sources no problem but the json feed is not being displayed. I'm wondering if its because I'm using a static json file to test or maybe I left out something, or is the json formatted wrong. Do I need to code a json feed in java to test (working with java)? These are the things I've looked at and I've looked at the other links regarding fullcalendar and json and none helped. If someone could give me a little help it would greatly appreciated.
feed.json
{
"events":
[
{
"id": "0",
"title": "Business Lunch",
"start": "2015-09-03T13:00:00",
"end": "2015-09-03T14:00:00",
"constraint": "businessHours"
},
{
"id": "2",
"title": "Conference",
"start": "2015-09-18",
"end": "2015-09-19",
"constraint": "businessHours"
},
{
"id": "3",
"title": "Party",
"start": "2015-09-29T20:00:00",
"end": "2015-09-29T24:00:00",
"constraint": "businessHours"
}
]
}
code sample
eventSources: [
// your event source
//feed source
{
url: '/hairzone/feed.json',
type: 'GET', //GET or POST
dataType: 'json',
data: {
custom_param1: 'something',
custom_param2: 'somethingelse'
},
error: function() {
alert('there was an error while fetching events!');
},
color: 'yellow', // a non-ajax option
textColor: 'black' // a non-ajax option
},
// any other sources...
{
googleCalendarId: 'some calendar id',
color: 'pink', // an option!
textColor: 'black', // an option!
//rendering: 'background'
overlay:false
},
// any other sources...
{
googleCalendarId: 'some calendar id',
color: 'blue', // an option!
textColor: 'black', // an option!
rendering: 'background',
overlay:false
}
]
I solved the problem. It seems that the feed is not formatted properly for fullcalendar. It just need everything starting with the brackets. Doesn't matter if its a static file or generated feed.
[
{
"id": "0",
"title": "Business Lunch",
"start": "2015-09-03T13:00:00",
"end": "2015-09-03T14:00:00",
"constraint": "businessHours"
},
{
"id": "2",
"title": "Conference",
"start": "2015-09-18",
"end": "2015-09-19",
"constraint": "businessHours"
},
{
"id": "3",
"title": "Party",
"start": "2015-09-29T20:00:00",
"end": "2015-09-29T24:00:00",
"constraint": "businessHours"
}
]

Gatling: JsonPath extract multiple values

I'm building a gatling 2.1.3 scenario and I need to extract data from a json body.
Example of the body:
[
{
"objectId": "FirstFoo",
"pvrId": "413"
"type": "foo",
"name": "the first name",
"fooabilities": {
"foo1": true,
"foo2": true
},
"versions": [23, 23, 23, 23, 23, 23, 24, 23, 23],
"logo": [
{
"type": "firstlogo",
"width": 780,
"height": 490,
"url": "firstlogos/HD/{resolution}.png"
}
]
},
{
"objectId": "SecondFoo",
"pvrId": "414"
"type": "foo",
"name": "the second name",
"fooabilities": {
"foo1": true,
"foo2": false
},
"versions": [23, 23, 23, 23, 23, 23, 24, 23, 23],
"logo": [
{
"type": "secondlogo",
"width": 780,
"height": 490,
"url": "secondlogos/HD/{resolution}.png"
}
]
}
]
and I have this code trying to extract de data:
exec(
http("get object")
.get(commons.base_url_ws + "/my-resource/2.0/object/")
.headers(commons.headers_ws_session).asJSON
.check(jsonPath("$..*").findAll.saveAs("MY_RESULT"))) (1)
.exec(session => {
foreach("${MY_RESULT}", "result") { (2)
exec(session => {
val result= session("result").as[Map[String, Any]]
val objectId = result("objectId")
val version = result("version")
session.set("MY_RESULT_INFO", session("MY_RESULT_INFO").as[List[(String,Int)]] :+ Tuple2(objectId, version))
})
}
session
})
My goal is:
To extract the objectId and the 9th value from the version array.
I want it to look as Vector -> [(id1, version1),(id2, version2)] in the session to reuse later in another call to the API.
My concerns are:
(1) Is this going to create entries in the session with the complete sub objects? Because in other answers I was that is was always a map that was saved ("id" = [{...}]) and here I do not have ids.
(2) In the logs, I see that the session is loaded with a lot of data, but this foreach is never called. What could cause this ?
My experience in Scala is of a beginner - there may be issues I did not see.
I have looked into this issue: Gatling - Looping through JSON array and it is not exactly answering my case.
I found a way to do it with a regex.
.check(regex("""(?:"objectId"|"version"):"(.*?)",.*?(?:"objectId"|"version"):\[(?:.*?,){9}([0-9]*?),.*?\]""").ofType[(String, String)].findAll saveAs ("OBJECTS")))
I can then use this
foreach("${OBJECTS}", "object") {
exec(
http("Next API call")
.get(commons.base_url_ws + "/my-resource/2.0/foo/${object._1}/${object._2}")
[...]
}

How to retrieve/display title, units, copyright along with JSON data in Highcharts

I have successfully implemented code for a JSONP request, retrieving data for multiple countries and displaying them as lines in a chart.
However, I would need to get the title, units, copyright etc. from the JSON as well, to be able to display that elements on the graph too.
Now, I wonder how this could be done.
The JSON response could look like this:
[
[
"series",
[
{
"data": [
[
2007,
2239300
],
[
2008,
2237490
],
[
2009,
2167070
],
[
2010,
2204450
]
],
"name": "France"
},
{
"data": [
[
2007,
2324234
],
[
2008,
3456352
],
[
2009,
1241422
],
[
2010,
4543231
]
],
"name": "Germany"
}
]
],
[
"title",
{
"text": "Title here"
}
],
[
"yAxis",
{
"text": "The units here"
}
]
]
My client's code would need to be changed then. For the moment it looks like this:
$.getJSON(url, {selectedCountries: "France,Germany,Switzerland", type: "jsonp"})
.done(function(data)
{
options.series = data;
var chart = new Highcharts.Chart(options);
})
.fail(function(jqxhr, textStatus, error)
{
var err = textStatus + ", " + error;
console.log( "Request Failed: " + err );
})
And I guess it must turn into something like this:
options.series = data['series']['data'];
options.title = data['title'];
But that doesn't work. Could anyone give me a hint what I should do? Thanks a lot!
Ok, got it going finally. One has to pass the JSON as an object (and not an array, and neither as string (so, no quotes like ' or " around the object!). Works like a charm here on fiddle.
Here the code:
$(function () {
var options = {
chart: {
renderTo: 'container',
type: 'spline',
marginBottom: 50
},
series: [{}]
};
data = {
"title": {
"text": "Here goes the title"
},
"yAxis": {
"title": {
"text": "Here go the units"
}
},
"series": [{
"name": "France",
"data": [[2006,2189260],[2007,2239300],[2008,2237490],[2009,2167070],[2010,2204450]]
}]
};
options.series = data["series"];
options.title = data["title"];
options.yAxis = data["yAxis"];
var chart = new Highcharts.Chart(options);
});
Thanks a lot for Sebastian Bochan's great support!

jqgrid won't load json data

I am new to jqgrid and am trying to use json to load the data. I have tried to use the jqgrid demos as a base and then build from there. The json data looks good, but I can't get anything loaded into the grid. Any ideas? I was hoping the use of loaderror or loadcomplete would at least give me insight, but I am not able to retrieve any message why the grid won't load.
json data:
{
"page": "1",
"total": 1,
"records": "12",
"rows": [
[
"67",
"3 - Sandbox: Appointment Set"
],
[
"68",
"1 - Sandbox: Email requested"
],
[
"69",
"2 - Sandbox: Questions not answered"
],
[
"74",
"1 - TenPointSix: Email requested for more information"
],
[
"75",
"2 - TenPointSix: Registered for webinar2"
],
[
"76",
"3 - TenPointSix: Webinar registration confirmed"
],
[
"93",
"5-Test Entry"
],
[
"94",
"test3"
],
[
"95",
"test2"
],
[
"97",
"Jeff"
],
[
"103",
"sortorder"
],
[
"106",
"reload"
]
]
}
My grid code:
<table id="jsonmap"></table>
<div id="pjmap"></div>
<script language="JavaScript" type="text/javascript">
jQuery("#jsonmap").jqGrid({
url:'sampleLoad.php?client=<?=$clientId5?>',
datatype: "json",
ajaxGridOptions: { contentType: 'application/json; charset=utf-8' },
colNames:['Inv No','Name'],
colModel:[
{name:'id',index:'id', width:55},
{name:'name',index:'name', width:100}
],
rowNum:15,
rowList:[15,30,45],
pager: '#pjmap',
sortname: 'id',
viewrecords: true,
sortorder: "asc",
jsonReader: {
root: "Rows",
cell: "",
page: "Page",
total: "Total",
records: "Records",
repeatitems: false,
id: "0"
},
loadComplete: function() {
alert("Load Complete");
},
loadError: function(xhr,st,err) { $("#jsonmapMessage").html("Type: "+st+"; Response: "+ xhr.status + " "+xhr.statusText); },
caption: "JSON Mapping",
width: '900',
height: '300'
});
jQuery("#jsonmap").jqGrid('navGrid','#pjmap',{edit:true,add:false,del:false});
Any help would be appreciated.
Thanks,
Jeff
The problem is the wrong jsonReader which you use. For example you use rows in the JSON data, but use root: "Rows". The format of the data corresponds default repeatitems: true property, but you used repeatitems: false and so on.
The correct jsonReader is
jsonReader: {
cell: "",
id: "0"
}
Additionally I would recommend you to add gridview: true and use height: 'auto' instead of height: '300' which simplify the setting of height.
The demo shows the modifications.

jqgrid datetime column sorting in 24 hour format

I am using a json object as follows from spring MVC to populate the jqgrid by using a json reader.
{
"rows": [
{
"id": 1,
"startTime": "Mar 4 08:00",
"projectId": "Proj_001",
"customerId": "Cust1",
"divisionId": "Div1"
},
{
"id": 2,
"startTime": "Mar 5 15:00",
"projectId": "Proj_001",
"customerId": "Cust1",
"divisionId": "Div1"
},
{
"id": 3,
"startTime": "Apr 14 22:00",
"projectId": "Proj_001",
"customerId": "Cust1",
"divisionId": "Div1"
}
]
}
I need to sort the
startTime
column which comes in 24hour time format (as above in the json object). i tried do some workaround but still unable to succeed.
jqgrid code -
{name:'startTime', index:'startTime', width:90,align:"left",sorttype:'datetime',datefmt:'M d, Y at h:i',sortable: true,editrules:{date:true} },
i will not using AM/PM notation here. i saw in jqgrid.base.js it uses AM/PM notation to sort. can anyone please shed some light on this? i was unable to find any jqgrid example for using date with 24hour time format that will do sort. Thank you in advance.
my jqgrid code -
jq(function(){
jq("#testgrid").jqGrid({
url:"/getall.html",
datatype: 'json',
mtype: 'GET',
colNames:['Id','Start Time','Cust.Id','Div.Id','Proj.Id'],
colModel :[
{name:'id', index:'id', width:90,align:"left",hidden: true},
{name:'startTime', index:'startTime', width:90, align:"left",
sorttype:'datetime', datefmt:'M d h:i',sortable: true,
editrules:{date:true}},
{name:'divisionId', index:'divisionId', width:100,align:"left"},
{name:'departmentId', index:'departmentId', width:120,align:"left"},
{name:'projectId', index:'projectId', width:100,align:"left"},
],
pager: '#testpager',
loadonce: true,
sortname: 'projectId',
sortorder: 'asc',
viewrecords: true,
multiselect: true,
//to hide pager buttons
pgbuttons:false,
recordtext:'',
pgtext:'',
gridview: true,
caption: 'my JQGRID',
jsonReader : {
root: "rows",
page: "page",
total: "total",
records: "records",
repeatitems: false,
cell: "cell",
id: "id"
}
});
//toolbar search
//jq("#testgrid").jqGrid('filterToolbar',
// {stringResult:true,searchOnEnter:false});
});
As I try to reproduce your problem all seems working correct. See the demo live here. If you will sort by the "Start Time" column all work without any problem which I could see.