JSON format for subgrid - json

hello can any one tell me the json format for local data containing the subgrid values.
i used following format but subgrid data is not loading into the subgrid table.
var data=[{"Left_ssr_id":CaGM33098,"Mismatches":"6","Gaps":"1","AlignLen":"1119","Identity":"99.37","right_ssr_start":17308507,"Qstart":"33","query":"AB-Contig743","subject":"Ca7","Send":"17305359","Score":"2113","Evalue":"0.0","Left_ssr_end":17293825,"right_ssr_end":17308542,"right_ssr_id":CaGM33099 ,"Sstart":"17304241","Qend":"1150","Left_ssr_start":17293811,subgrid:[{"Right_ssr_start":17308507,"Right_ssr_end":17308542},{"Right_ssr_start":17308506,"Right_ssr_end":17308543}]}]
code used to upload the data . The Grid is getting the data but subgrid showing only the header and the blank rows.
$(document).ready(function(){
$("#blastform").submit(function(){
jQuery.ajax({
data: $(this).serialize(),
url: this.action,
type: this.method,
dataType: "json",
error: function() {
$(thistarget).html("<span class='error'>Failed to submit form!</span>");
},
success: function(res) {
var data=res;
$("#datatable").jqGrid({
datatype:"local",
data:data,
colNames:['QueryID','SubjectID', . . . 'Right_nearest_distance'],
colModel:[ {name:'query',index:'query', width:55},
{name:'subject',index:'subject', width:80},
.,
.,
{name:'right_near_dist',index:'right_near_dist', width:50, sortable:false}, ],
rowNum:100,
rowList:[100,200,500],
pager: $('#pager2'),
sortname: 'QueryID',
viewrecords: true,
sortorder: 'desc',
loadonce: true,
altRows: true,
pgbuttons: true,
subGrid : true,
subGridUrl: 'local',
subGridRowExpanded: function(subgrid_id, row_id)
{
var subgrid_table_id, pager_id;
subgrid_table_id = subgrid_id+"_t";
pager_id = "p_"+subgrid_table_id;
$("#"+subgrid_id).html("<table id='"+subgrid_table_id+"' class='scroll'></table><div id='"+pager_id+"' class='scroll'></div>");
jQuery("#"+subgrid_table_id).jqGrid({
datatype: "local",
colNames: ['ssr_start','ssr_end'],
colModel: [ {name:"Right_ssr_start",index:"Right_ssr_start",width:80,key:true},
{name:"Right_ssr_end",index:"Right_ssr_end",width:130},
],
rowNum:20,
pager: pager_id,
sortname: 'ssr_start',
sortorder: "asc",
height: '100%' });
jQuery("#"+subgrid_table_id).jqGrid('navGrid',"#"+pager_id,{edit:false,add:false,del:false}) },
caption: 'Blast Results'
});
$("#datatable").jqGrid('navGrid','#pager2', {position: 'right'});
jQuery("#datatable").jqGrid('navGrid','#blastresults',{edit:false,add:false,del:false});
}
})
return false;
}
);
);

You need to configure the localReader settings
see http://www.trirand.com/jqgridwiki/doku.php?id=wiki:retrieving_data#array_data

I don't recommend you to make separate ajax call and to use datatype: "local", data: data. You will have many disadvantages. jqGrid provide datatype: "json" type for the case. One can use additional options like jsonReader and jsonmap to inform jqGrid how to get information about grid data from the server response.
The value for var data which you posted provide wrong data. You use variables CaGM33098 and CaGM33099 which are undefined. If you used cut&pased from the server response, then you generate wrong JSON response on the server. Moreover it's strange that subgrid if the item from data array isn't enclosed in ". Probably the server returns from this.action (??? what is this here???) the following data
[
{
"Left_ssr_id": "CaGM33098",
"Mismatches": "6",
"Gaps": "1",
"AlignLen": "1119",
"Identity": "99.37",
"right_ssr_start": 17308507,
"Qstart": "33",
"query": "AB-Contig743",
"subject": "Ca7",
"Send": "17305359",
"Score": "2113",
"Evalue": "0.0",
"Left_ssr_end": 17293825,
"right_ssr_end": 17308542,
"right_ssr_id": "CaGM33099",
"Sstart": "17304241",
"Qend": "1150",
"Left_ssr_start": 17293811,
"subgrid": [
{
"Right_ssr_start": 17308507,
"Right_ssr_end": 17308542
},
{
"Right_ssr_start": 17308506,
"Right_ssr_end": 17308543
}
]
}
]
The old answer and the answer shows how one can implement displaying nested data as subgrid. Another answer shows how to use userdata to load nested data directly from the server. I recommend you to use the last approach.

Related

How to reuse json in RAML example

I have the following files
user.json
"user": {
"id": 1,
"name": "nameuser",
"online": true,
"profile": {
"photo": "",
"validated": true,
"popular": true,
"suspect": false,
"moderator": false,
"age": "22 ani",
"gender_id": "M"
}
}
profile.raml
displayName: Profile
get:
description: Get profile data
queryParameters:
userId:
description: The user id for which we are requesting the profile data
type: integer
required: true
responses:
200:
body:
application/json:
example: |
{
"user": !include user.json,
"details": {
"friend": true
}
}
The user json is present in more examples and I want to reuse it.
I'm using raml2html and it compiles it to
so how do I do this ?
I have used parameters successfully in the past. You will not be able to put a parameter inside an included file because RAML views all included files as strings. But you can do something like this in your profile.raml:
example: |
{
"user": <<userItem>>,
"details": {
"friend": true
}
}
The RAML 200 Tutorial has a good explanation and code examples (see snippets below) on how to declare parameters and them pass them in. I highly recommend reading the entire tutorial though.
resourceTypes:
- collection:
description: Collection of available <<resourcePathName>> in Jukebox.
get:
description: Get a list of <<resourcePathName>>.
responses:
200:
body:
application/json:
example: |
<<exampleCollection>>
/songs:
type:
collection:
exampleCollection: !include jukebox-include-songs.sample

jQuery dataTables - TableTools not working

I'm using http://datatables.net/extensions/tabletools/ in my local-host ( wamp server ). It's working fine, but when I put the same code on my online server, it isn't working.
I am using all latest version of datatables
tableTools: {
"sSwfPath": "https://datatables.net/release-datatables/extensions/TableTools/swf/copy_csv_xls_pdf.swf",
"sRowSelect": "os",
"sRowSelector": 'td:first-child',
// "aButtons": [ "copy", "csv", "xls","pdf","print","select_all", "select_none" ]
"aButtons": [
"copy",
"print", {
"sExtends": "collection",
"sButtonText": "Save", // button name
// "aButtons": [ "csv", "xls", "pdf" ]
"aButtons": [
"csv",
"xls", {
"sExtends": "pdf",
"sPdfOrientation": "landscape",
"sPdfMessage": "List of product."
},
"print"
]
}
]
}
Firstly there was no click on copy, pdf, csv, xls button. Hence I taught my path or swf is not working hence I replaced the link with online link. Hence now I get click, but when I click Copy button it gives me a message ... but when I past in my notepad it's giving me "blank ". Also my pdf, csv, xlsx is not working. Only Print is working perfect. Please let me know what is the issue as in my localhost all is working fine. Its creating issues in my online server.
I am pretty sure that datatables.net actively is blocking for use of the .swf. Allan Jardine has commented the direct use of the .swf files several times :
datatables.net is not a CDN server and should not be used as such. It
is not designed to be, and I might add throttling for hotlinking in
future as a huge amount of bandwidth is being used and causing
unnecessary load. You'll get much better performance from using a
proper CDN or even a locally hosted file.
However, with the introduction of 1.10.x there is finally established a real CDN server, including all the TableTools resources -> http://cdn.datatables.net/tabletools/2.2.2/
So replace the sSwfPath with :
http://cdn.datatables.net/tabletools/2.2.2/swf/copy_csv_xls_pdf.swf
I meant you should post it as a completely new question, since it in fact is a new question! :) Anyway. The problem is, that you'll need to render the data, when you produce a PDF. Otherwise you will just get some $(element).text() output, including the select and its options. Like this :
"aButtons": [
"copy",
"csv",
"xls",
{ "sExtends": "pdf",
"fnCellRender": function ( sValue, iColumn, nTr, iDataIndex ) {
//extract the value of the select
if ( iColumn === 7 ) {
var val=$(sValue).find('select').val();
return (val!=='') ? val : 'not set';
}
//create a dummy text for the HTML-link
if ( iColumn === 8 ) {
return 'click';
}
return sValue;
}
},
"print",
"select_all",
"select_none"
]
see your code here (as close I can get) -> http://jsfiddle.net/3F8ZJ/.
However, you still have a problem caused by your mRender rendering, so the column positions is messing up. It breaks the internal <table>-structure. Why are you inserting extra <td>..</td>? But have not time to look into this at the moment.
As i want to show proper code format hence post as new answer
# DAVIDKONRAD : i got to know when i remove columnDefs from below code then my PDF shows proper records ... btw my csv , excel , print diplay proper record with columnDefs .. only pdf is not showing proper record with "columnDefs"
and i got to know the word which is seen " select " is because of that only ..as i have use dropdown in columndefs
dt = $('#example').DataTable( {
"dom": '<"clear">T<"clear"><"clear">lfrtip',
"pagingType": "full_numbers",
"scrollY": "440px",
"scrollX": "100%",
"scrollCollapse": true,
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "includes/db/server_processing.php",
"deferRender": true,
"aaSorting":[[0, "desc"]],
"aoColumns": [
{ className: "center", },
{ className: "center", },
{ className: "center", },
{ className: "center", },
{ className: "center", },
{ className: "center", },
{ className: "center", },
],
"columnDefs": [
{
"aTargets":[7],
"fnCreatedCell": function(nTd, sData, oData, iRow, iCol)
{
$(nTd).css('text-align', 'center');
},
"mData": null,
"mRender": function( data, type, full) {
return '<td><select id="dynamic_select_'+full[0]+'" name="dynamic_select_'+full[0]+'">\n\
<option id="0" value="">Select</option/>\n\
<option id="1_'+full[0]+'" value="test.php?id='+full[0]+'">10</option/>\n\
<option id="2_'+full[0]+'" value="test2.php?id='+full[0]+'">12</option/>\n\
<option id="3_'+full[0]+'" value="test3.php?id='+full[0]+'">13</option/>\n\
</select></td>';
//return '<button>Click!</button>';
}
},
{
"aTargets":[8],
"fnCreatedCell": function(nTd, sData, oData, iRow, iCol)
{
$(nTd).css('text-align', 'center');
},
"mData": null,
"mRender": function(data, type, full){
//return '<button>Click!</button>';
return '<div id="container">Click</div>';
}
}
]
} );

How to load multidimensional / nested json into a store?

So I'm trying to load the data received from a webservice into a sencha touch 2 store.
The data is nested JSON, however it is made to include multiple dataArrays.
I am working with sencha touch 2.3.1, somewhat equal to Ext JS 4.2. I don't have that much experience with sencha yet, but I'm getting there. I decided to go for MVC, so I'd like the answers to be as close to this as possible :).
This is the example JSON I am using:
[
{
"DataCollection": {
"DataArrayOne": [
{
"Name": "John Smith",
"Age": "19"
},
{
"Name": "Bart Smith",
"Age": "16"
}
],
"DataArrayTwo": [
{
"Date": "20110601",
"Product": "Apple",
"Descr": "",
"Remark": ""
},
{
"Date": "20110601",
"Product": "Orange",
"Descr": "",
"Remark": ""
},
{
"Date": "20110601",
"Product": "Pear",
"Descr": "",
"Remark": ""
}
],
"DataArrayThree": [
{
"SomeTotalCost": "400,50",
"IntrestPercentage": "3"
}
]
}
}
]
Through only one call, I get this json. I don't want to cause any unnecessary traffic so I hope to be able to use the data somehow.
I want to be able to use each DataArray on its own.
The data gets sent to the store through its proxy:
Ext.define("MyApp.store.myDataObjects", {
extend: "Ext.data.Store",
config: {
model: "MyApp.model.myDataObject",
proxy: {
reader: {
type: "json",
rootProperty: "DataCollection"
},
type: "ajax",
api: {
read: "https://localhost/Service.svc/json"
},
limitParam: false,
startParam: false,
pageParam: false,
extraParams: {
id: "",
token: "",
filter: ""
},
writer: {
encodeRequest: true,
type: "json"
}
}
}
});
I am a bit stuck with the model here. I tried using mappings which would look like this:
config: {
fields: [ {
name: "IntrestPercentage",
mapping: "Calculation.IntrestPercentage",
type: "string"
}
]}
I tried associations as well but to no avail.
According to google chrome console, it doesn't make any objects containing data. I get only 1 object with all values "null".
My endgoal is to be able to show each dataArray in a separate table. So a table for DataArrayOne, a table for DatarrayTwo... The data itself isn't linked. They are only details that have to be shown on a view.
John Smith isn't related to the apples, as in he didn't buy. The apples are just there as an item to be shown.
The possible solutions I've seen yet not understood due to them being outdated are:
ChildStores: You have a master store that receives the data, and then
you split the data to other stores according to rootProperty. I have
no idea how to do this however and I'm not sure if it will work at
all.
Associations, in case I was doing them wrong. I don't think they
are needed because the data isn't linked to each other but it is part
of "DataCollection" though.
Could someone please post an example on how to deal with this unusual(?) kind of nested json.
Or any other solution which will lead to being able to use the 3 dataArrays at will.
Thanks in advance
The best would be to load the complete data with a separate Ext.Ajax.request and then use store.loadData in the success callback. For example:
var data = Ext.decode(response.responseText);
store1.loadData(data[0].DataCollection.DataArrayOne);
store2.loadData(data[0].DataCollection.DataArrayTwo);
store3.loadData(data[0].DataCollection.DataArrayThree);

JQGrid can not load json data from action

I have problem when loading data from action to jqGrid
My action return JSON data:
{"page":"1","records":"31","rows":["{'id':'1','cell':['1','Cant open destop','Destop','Easy','duongls','huyld','minhnq','Finance ','Open']}","{'id':'2','cell':['2','Cant log to email','Email','Normal','thangtd','minhnq','longnh','Secretary ','Assigned']}","{'id':'3','cell':['3','No internet access Edited ver 2 longnh','Connection','Hard','thangtd','longnh','longnh','Secretary ','Closed']}","{'id':'4','cell':['4','Request password','Account','Normal','dungtq','honglm','longnh','Director','Cancelled']}","{'id':'5','cell':['5','Cant open latop','Laptop','Hard','duongls','huyld','minhnq','Director','Closed']}","{'id':'6','cell':['6','issue 11111111111111','','','dungtq','longnh','','Planning','Open']}","{'id':'7','cell':['7','Issue ku minh heo','','','dungtq','longnh','','Planning','Open']}","{'id':'8','cell':['8','New ticket 12345','','','dungtq','longnh','','Planning','Open']}","{'id':'9','cell':['9','Mail server cannot connect','','','haitct','longnh','','Director','Open']}","{'id':'10','cell':['10','aaaaaaaaaaaa','','','dungtq','longnh','','Planning','Open']}"],"total":"4"}
and in JSP I call jqgrid:
$("#list1").jqGrid({
url: "<%=request.getContextPath()%>/pagingIssue?time='+new Date().getTime()",
colNames:['Id','Name', 'Type','Severity', 'Owner','Register', 'Responsor', 'Department','Status'],
colModel:[
{name:'issId',index:'issId', width:40,sortable:true},
{name:'issName',index:'issName', width:200,sortable:true},
{name:'issType',index:'issType', width:100,sortable:true},
{name:'issSeverity',index:'issSeverity', width:100,sortable:true},
{name:'issOwner',index:'issOwner', width:80,sortable:true},
{name:'issRegister',index:'issRegister', width:100,sortable:true},
{name:'issResponsor',index:'issResponsor', width:100,sortable:true},
{name:'department',index:'department', width:120,sortable:true},
{name:'issStatus',index:'issStatus', width:80,sortable:true}],
rowNum:10,
rowList:[10,15,20],
pager: '#pager1',
sortname: 'issId',
datatype: 'json',
recordpos: 'left',
viewrecords: true,
sortorder: 'desc',
multiselect: true,
caption: 'Issue List' });
});
The grid just show Loading...
Can you help me?
By default, your JSON data should be in the format noted in the jqGrid documentation for JSON Data:
{
"total": "xxx",
"page": "yyy",
"records": "zzz",
"rows" : [
{"id" :"1", "cell" :["cell11", "cell12", "cell13"]},
{"id" :"2", "cell":["cell21", "cell22", "cell23"]},
...
]
}
Your data is close, but rows contains a string
"rows":["{'id' ... ]}"]
instead of an object:
"rows":[{'id' ... ]}]
Also, you should always use double quotes for strings, and never single-quotes (see the state machine diagrams at json.org for more details). So your JSON should look like this:
"rows":[{"id" ... ]}]

Mapping JSON data in JQGrid

I am using jqGrid 3.6.4 and a jquery 1.4.2 . in my sample i am getting following json data format & i want to map these json data into rows of a jqgrid
{
"page": "1",
"total": 1,
"records": "6",
"rows": [
{
"head": {
"student_name": "Mr S. Jack ",
"year": 2007
},
"sub": [
{
"course_description": "Math ",
"date": "22-04-2010",
"number": 1,
"time_of_add": "2:00",
"day": "today"
}
]
}
]
}
my jqgrid code is as follows
jQuery("#"+subgrid_table_id).jqGrid({
url:"http://localhost/stud/beta/web/GetStud.php?sid="+sid,
dtatype: "json",
colNames: ['Stud Name','Year','Date'.'Number'],
colModel: [ {name:'Stud Name',index:'student_name', width:100, jsonmap:"student_name"},
{name:'Year',index:'year', width:100, jsonmap:"year"},
{name:'Date',index:'date', width:100, jsonmap:"date"},
{name:'Number',index:'number', width:100, jsonmap:"number"}
],
height:'100%',
jsonReader: { repeatitems : false, root:"head" },
});
So now the problem is as my data i.e. student_name and year is under "head" , the jqgrid is enable to locate these two fields. at the same time other two column values i.e. Date and Number lies under "sub" and even those columns i am not be able to map it with jqgrid
so kindly help me how to located these attributes in JQGrid.
Thanks
First of all the code posted has some errors like dtatype: "json" instead of datatype: "json". "},});" instead of "}});" at the end of code and colNames: ['Stud Name','Year','Date'.'Number'] instead of colNames: ['Stud Name','Year','Date','Number']. After fixing this clear bugs you need change jsonmap values. This was your main question. The fixed code will be look like following:
jQuery("#"+subgrid_table_id).jqGrid({
...
datatype: 'json',
colNames: ['Stud Name','Year','Date'.'Number'],
colModel: [
{name:'student_name', width:100, jsonmap:"head.student_name"},
{name:'year', width:100, jsonmap:"head.year"},
{name:'date', width:100, jsonmap:"sub.0.date"},
{name:'number', width:100, jsonmap:"sub.0.number"}
],
jsonReader: { repeatitems:false, root:"rows" }
});
You have to fix root to "rows" and use jsonmap in JSON dot notation (see http://www.trirand.com/jqgridwiki/doku.php?id=wiki:retrieving_data#json_dot_notation). I use a little strange notation like "sub.0.number" because sub.0.number in JavaScript is the same as sub[0].number. It works now.
I recommend you think one more about the structure of JSON data which you receive. (see my previous comments to you question): Is "sub" element is really an array with always one element or you want to use subgrids? Probably the data should be changed from sub:[{"":"", ...}] to sub:{"":"", ...}? What do you want to use as a rowid? student_name? Then add id: "head.student_name" to the jsonReader definition or add key: true property to the definition of the column student_name. Or you forget to include it in the JSON data?
And the last suggestion. If you open http://trirand.com/blog/jqgrid/jqgrid.html and opens on the left side of tree the branch "Data Mapping" \ "Data optimization" you will see an example where on use only array instead of named elements in JSON. Such data will be have minimum size and can be transferred more quickly from server to client. You data instead have some fields (like "course_description") which you don't use at all. So if you can make any changes in the server code try to optimize the data transfer rate.