[web2py] Re: Populating jqGrid Tree with JSON
Thanks for all the input. I really read the docs. There were heaps of mistakes in my code. Now solved and for what its\worth I append the working code. Once again Thanks guys! VIEW {{extend 'layout.html'}} script type=text/javascript jQuery(document).ready(function(){ $('#treeGrid').jqGrid({ url: {{=URL(r=request,f='call',args=['json','treet'])}}, contentType: application/json; charset=utf-8, postData:[], datatype: json, height: auto, mType: 'GET', treeGridModel: 'adjacency', colNames: [ 'id', 'Prestations', 'neigh'], colModel: [ {name: 'id', width: 100, key: true, hidden: false}, {name: 'elementName', width: 785, sortable: false}, {name: 'neighbourhood', width: 785, hidden: false} ], sortname: 'id', sortorder: asc, treeGrid: true, caption: Menu, ExpandColumn: elementName, ExpandColClick:true, jsonReader: { root: row, cell:'', repeatitems: false, userdata: userdata}, onSelectRow: function(rowid) { var row = $(this).getLocalRow(rowid); // do something with row alert(Name: + row.elementName + Hood: + row.neighbourhood) }, autowidth: true }); }); /script div style=width:180px; table id=treeGrid/ CONTROLLER @service.json def tree(): import json response.files.append(http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.1/themes/redmond/jquery-ui.css;) response.files.append(http://www.ok-soft-gmbh.com/jqGrid/jquery.jqGrid-4.4.4/css/ui.jqgrid.css;) response.files.append(http://code.jquery.com/jquery-1.9.1.js;) response.files.append(http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.1/jquery-ui.js;) response.files.append(http://www.ok-soft-gmbh.com/jqGrid/jquery.jqGrid-4.4.4/js/i18n/grid.locale-en.js;) response.files.append(http://www.ok-soft-gmbh.com/jqGrid/jquery.jqGrid-4.4.4/js/jquery.jqGrid.src.js;) rows = db(db.neighbourhood.id 0).select().as_list() concat = '{response:[' seq =1 source = dict() vals = [] for row in rows: row['id'] = seq extra = {'neighbourhood': row.get('elementName'),} row.update(extra) print row vals.append(row) seq = seq+1 innerrows = db(db.report.parent == row.get('id')).select().as_list() for innerrow in innerrows: innerrow.update(extra) print innerrow innerrow['id'] = seq vals.append(innerrow) seq = seq+1 return dict(row=vals) On Thursday, March 28, 2013 6:42:56 AM UTC+11, Willoughby wrote: Oops - completely missed the 'no javascript' part. It would appear it's not loading your jquery/jqgrid scripts. Are you loading them in layout.html? See this: http://www.trirand.com/jqgridwiki/doku.php?id=wiki:how_to_install On Monday, March 25, 2013 6:51:10 PM UTC-4, Nate wrote: Nothing in the console. Firebug reports No Javascript on this pageIf script tags have a type attribute, it should equal text/javascript or application/javascript. Also scripts must be parsable (syntactically correct). On Monday, March 25, 2013 11:15:31 PM UTC+11, Willoughby wrote: Do you get any errors in the console? That's the first place I usually look... On Sunday, March 24, 2013 8:42:45 PM UTC-4, Nate wrote: Hi I have a controller sending JSON to my view. I cannot get the data into the TreeGrid. The Json is coming down correctly (I placed it manually and it works). Running this code places the JSON on the webpage. Controller and View below. Help appreciated. Regards Nate CONTROLLER @service.json def get_report(): import json rows = db(db.neighbourhood.id 0).select().as_list() concat = '{response:[' seq =1 for row in rows: row['id'] = seq concat = concat + json.dumps(row)+, seq = seq+1 innerrows = db(db.report.parent == row.get('id')).select().as_list() for innerrow in innerrows: innerrow['id'] = seq concat = concat + json.dumps(innerrow) + , seq = seq+1 concat = concat.strip( ',' ) concat = concat + ']},grid;' return concat VIEW {{extend 'layout.html'}} script type=text/javascript jQuery(document).ready(function(){ jQuery.getJSON({{=URL(r=request,f='call',args=['json','get_report'])}}, function(msg){ jQuery.each(msg, function(){ topicjson = this; $('#treeGrid').jqGrid({ datastr: topicjson, datatype: json, height: auto, mType: 'GET', treeGridModel: 'adjacency', colNames: [/*id,*/Items,url], colModel: [ {name: elementName, width:250, resizable: false}, {name: url,width:1,hidden:true} ], treeGrid: true, caption: Neighbourhood, ExpandColumn: name, ExpandColClick:true,
[web2py] Re: Populating jqGrid Tree with JSON
Here's the grid home: http://www.trirand.com/blog/ On Tuesday, March 26, 2013 1:38:00 PM UTC-4, Derek wrote: Where would one get this jqGrid Tree, and can you post a sample JSON dataset that this is supposed to work with? On Monday, March 25, 2013 3:51:10 PM UTC-7, Nate wrote: Nothing in the console. Firebug reports No Javascript on this pageIf script tags have a type attribute, it should equal text/javascript or application/javascript. Also scripts must be parsable (syntactically correct). On Monday, March 25, 2013 11:15:31 PM UTC+11, Willoughby wrote: Do you get any errors in the console? That's the first place I usually look... On Sunday, March 24, 2013 8:42:45 PM UTC-4, Nate wrote: Hi I have a controller sending JSON to my view. I cannot get the data into the TreeGrid. The Json is coming down correctly (I placed it manually and it works). Running this code places the JSON on the webpage. Controller and View below. Help appreciated. Regards Nate CONTROLLER @service.json def get_report(): import json rows = db(db.neighbourhood.id 0).select().as_list() concat = '{response:[' seq =1 for row in rows: row['id'] = seq concat = concat + json.dumps(row)+, seq = seq+1 innerrows = db(db.report.parent == row.get('id')).select().as_list() for innerrow in innerrows: innerrow['id'] = seq concat = concat + json.dumps(innerrow) + , seq = seq+1 concat = concat.strip( ',' ) concat = concat + ']},grid;' return concat VIEW {{extend 'layout.html'}} script type=text/javascript jQuery(document).ready(function(){ jQuery.getJSON({{=URL(r=request,f='call',args=['json','get_report'])}}, function(msg){ jQuery.each(msg, function(){ topicjson = this; $('#treeGrid').jqGrid({ datastr: topicjson, datatype: json, height: auto, mType: 'GET', treeGridModel: 'adjacency', colNames: [/*id,*/Items,url], colModel: [ {name: elementName, width:250, resizable: false}, {name: url,width:1,hidden:true} ], treeGrid: true, caption: Neighbourhood, ExpandColumn: name, ExpandColClick:true, autowidth: true }); }) }); }); /script div style=width:180px; table id=treeGrid /table -- --- You received this message because you are subscribed to the Google Groups web2py-users group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
[web2py] Re: Populating jqGrid Tree with JSON
Sorry if this is a repost - Google Groups is giving me fits I'm no expert, and my experience is limited to very old versions of both web2py and jqGrid. BUT in my setup, the grid block does a call to get data to populate the grid. I don't see a call in your grid block, like this snippet: (again this is old) jQuery(#accts).jqGrid({ !--this is the id used to position the grid in the html below-- imgpath: '/{{=request.application}}/static/themes/steel/images', !-- sets the theme used for the grid-- caption: 'Item Accounts', !-- text to display in the header-- {{if 'freeze' in request.vars:}} url: '../griddata/list_all_accounts?freeze=true', {{else:}} url: '../griddata/list_all_accounts', !-- this is an asyncronous call to get the data for the grid-- {{pass}} datatype: 'xml', !--the grid expects xml formatted data (see jqGrid docs for the default xml document structure)-- mtype: 'GET', On Monday, March 25, 2013 6:51:10 PM UTC-4, Nate wrote: Nothing in the console. Firebug reports No Javascript on this pageIf script tags have a type attribute, it should equal text/javascript or application/javascript. Also scripts must be parsable (syntactically correct). On Monday, March 25, 2013 11:15:31 PM UTC+11, Willoughby wrote: Do you get any errors in the console? That's the first place I usually look... On Sunday, March 24, 2013 8:42:45 PM UTC-4, Nate wrote: Hi I have a controller sending JSON to my view. I cannot get the data into the TreeGrid. The Json is coming down correctly (I placed it manually and it works). Running this code places the JSON on the webpage. Controller and View below. Help appreciated. Regards Nate CONTROLLER @service.json def get_report(): import json rows = db(db.neighbourhood.id 0).select().as_list() concat = '{response:[' seq =1 for row in rows: row['id'] = seq concat = concat + json.dumps(row)+, seq = seq+1 innerrows = db(db.report.parent == row.get('id')).select().as_list() for innerrow in innerrows: innerrow['id'] = seq concat = concat + json.dumps(innerrow) + , seq = seq+1 concat = concat.strip( ',' ) concat = concat + ']},grid;' return concat VIEW {{extend 'layout.html'}} script type=text/javascript jQuery(document).ready(function(){ jQuery.getJSON({{=URL(r=request,f='call',args=['json','get_report'])}}, function(msg){ jQuery.each(msg, function(){ topicjson = this; $('#treeGrid').jqGrid({ datastr: topicjson, datatype: json, height: auto, mType: 'GET', treeGridModel: 'adjacency', colNames: [/*id,*/Items,url], colModel: [ {name: elementName, width:250, resizable: false}, {name: url,width:1,hidden:true} ], treeGrid: true, caption: Neighbourhood, ExpandColumn: name, ExpandColClick:true, autowidth: true }); }) }); }); /script div style=width:180px; table id=treeGrid /table -- --- You received this message because you are subscribed to the Google Groups web2py-users group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
[web2py] Re: Populating jqGrid Tree with JSON
Oops - completely missed the 'no javascript' part. It would appear it's not loading your jquery/jqgrid scripts. Are you loading them in layout.html? See this: http://www.trirand.com/jqgridwiki/doku.php?id=wiki:how_to_install On Monday, March 25, 2013 6:51:10 PM UTC-4, Nate wrote: Nothing in the console. Firebug reports No Javascript on this pageIf script tags have a type attribute, it should equal text/javascript or application/javascript. Also scripts must be parsable (syntactically correct). On Monday, March 25, 2013 11:15:31 PM UTC+11, Willoughby wrote: Do you get any errors in the console? That's the first place I usually look... On Sunday, March 24, 2013 8:42:45 PM UTC-4, Nate wrote: Hi I have a controller sending JSON to my view. I cannot get the data into the TreeGrid. The Json is coming down correctly (I placed it manually and it works). Running this code places the JSON on the webpage. Controller and View below. Help appreciated. Regards Nate CONTROLLER @service.json def get_report(): import json rows = db(db.neighbourhood.id 0).select().as_list() concat = '{response:[' seq =1 for row in rows: row['id'] = seq concat = concat + json.dumps(row)+, seq = seq+1 innerrows = db(db.report.parent == row.get('id')).select().as_list() for innerrow in innerrows: innerrow['id'] = seq concat = concat + json.dumps(innerrow) + , seq = seq+1 concat = concat.strip( ',' ) concat = concat + ']},grid;' return concat VIEW {{extend 'layout.html'}} script type=text/javascript jQuery(document).ready(function(){ jQuery.getJSON({{=URL(r=request,f='call',args=['json','get_report'])}}, function(msg){ jQuery.each(msg, function(){ topicjson = this; $('#treeGrid').jqGrid({ datastr: topicjson, datatype: json, height: auto, mType: 'GET', treeGridModel: 'adjacency', colNames: [/*id,*/Items,url], colModel: [ {name: elementName, width:250, resizable: false}, {name: url,width:1,hidden:true} ], treeGrid: true, caption: Neighbourhood, ExpandColumn: name, ExpandColClick:true, autowidth: true }); }) }); }); /script div style=width:180px; table id=treeGrid /table -- --- You received this message because you are subscribed to the Google Groups web2py-users group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
[web2py] Re: Populating jqGrid Tree with JSON
Where would one get this jqGrid Tree, and can you post a sample JSON dataset that this is supposed to work with? On Monday, March 25, 2013 3:51:10 PM UTC-7, Nate wrote: Nothing in the console. Firebug reports No Javascript on this pageIf script tags have a type attribute, it should equal text/javascript or application/javascript. Also scripts must be parsable (syntactically correct). On Monday, March 25, 2013 11:15:31 PM UTC+11, Willoughby wrote: Do you get any errors in the console? That's the first place I usually look... On Sunday, March 24, 2013 8:42:45 PM UTC-4, Nate wrote: Hi I have a controller sending JSON to my view. I cannot get the data into the TreeGrid. The Json is coming down correctly (I placed it manually and it works). Running this code places the JSON on the webpage. Controller and View below. Help appreciated. Regards Nate CONTROLLER @service.json def get_report(): import json rows = db(db.neighbourhood.id 0).select().as_list() concat = '{response:[' seq =1 for row in rows: row['id'] = seq concat = concat + json.dumps(row)+, seq = seq+1 innerrows = db(db.report.parent == row.get('id')).select().as_list() for innerrow in innerrows: innerrow['id'] = seq concat = concat + json.dumps(innerrow) + , seq = seq+1 concat = concat.strip( ',' ) concat = concat + ']},grid;' return concat VIEW {{extend 'layout.html'}} script type=text/javascript jQuery(document).ready(function(){ jQuery.getJSON({{=URL(r=request,f='call',args=['json','get_report'])}}, function(msg){ jQuery.each(msg, function(){ topicjson = this; $('#treeGrid').jqGrid({ datastr: topicjson, datatype: json, height: auto, mType: 'GET', treeGridModel: 'adjacency', colNames: [/*id,*/Items,url], colModel: [ {name: elementName, width:250, resizable: false}, {name: url,width:1,hidden:true} ], treeGrid: true, caption: Neighbourhood, ExpandColumn: name, ExpandColClick:true, autowidth: true }); }) }); }); /script div style=width:180px; table id=treeGrid /table -- --- You received this message because you are subscribed to the Google Groups web2py-users group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
[web2py] Re: Populating jqGrid Tree with JSON
Do you get any errors in the console? That's the first place I usually look... On Sunday, March 24, 2013 8:42:45 PM UTC-4, Nate wrote: Hi I have a controller sending JSON to my view. I cannot get the data into the TreeGrid. The Json is coming down correctly (I placed it manually and it works). Running this code places the JSON on the webpage. Controller and View below. Help appreciated. Regards Nate CONTROLLER @service.json def get_report(): import json rows = db(db.neighbourhood.id 0).select().as_list() concat = '{response:[' seq =1 for row in rows: row['id'] = seq concat = concat + json.dumps(row)+, seq = seq+1 innerrows = db(db.report.parent == row.get('id')).select().as_list() for innerrow in innerrows: innerrow['id'] = seq concat = concat + json.dumps(innerrow) + , seq = seq+1 concat = concat.strip( ',' ) concat = concat + ']},grid;' return concat VIEW {{extend 'layout.html'}} script type=text/javascript jQuery(document).ready(function(){ jQuery.getJSON({{=URL(r=request,f='call',args=['json','get_report'])}}, function(msg){ jQuery.each(msg, function(){ topicjson = this; $('#treeGrid').jqGrid({ datastr: topicjson, datatype: json, height: auto, mType: 'GET', treeGridModel: 'adjacency', colNames: [/*id,*/Items,url], colModel: [ {name: elementName, width:250, resizable: false}, {name: url,width:1,hidden:true} ], treeGrid: true, caption: Neighbourhood, ExpandColumn: name, ExpandColClick:true, autowidth: true }); }) }); }); /script div style=width:180px; table id=treeGrid /table -- --- You received this message because you are subscribed to the Google Groups web2py-users group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
[web2py] Re: Populating jqGrid Tree with JSON
Nothing in the console. Firebug reports No Javascript on this pageIf script tags have a type attribute, it should equal text/javascript or application/javascript. Also scripts must be parsable (syntactically correct). On Monday, March 25, 2013 11:15:31 PM UTC+11, Willoughby wrote: Do you get any errors in the console? That's the first place I usually look... On Sunday, March 24, 2013 8:42:45 PM UTC-4, Nate wrote: Hi I have a controller sending JSON to my view. I cannot get the data into the TreeGrid. The Json is coming down correctly (I placed it manually and it works). Running this code places the JSON on the webpage. Controller and View below. Help appreciated. Regards Nate CONTROLLER @service.json def get_report(): import json rows = db(db.neighbourhood.id 0).select().as_list() concat = '{response:[' seq =1 for row in rows: row['id'] = seq concat = concat + json.dumps(row)+, seq = seq+1 innerrows = db(db.report.parent == row.get('id')).select().as_list() for innerrow in innerrows: innerrow['id'] = seq concat = concat + json.dumps(innerrow) + , seq = seq+1 concat = concat.strip( ',' ) concat = concat + ']},grid;' return concat VIEW {{extend 'layout.html'}} script type=text/javascript jQuery(document).ready(function(){ jQuery.getJSON({{=URL(r=request,f='call',args=['json','get_report'])}}, function(msg){ jQuery.each(msg, function(){ topicjson = this; $('#treeGrid').jqGrid({ datastr: topicjson, datatype: json, height: auto, mType: 'GET', treeGridModel: 'adjacency', colNames: [/*id,*/Items,url], colModel: [ {name: elementName, width:250, resizable: false}, {name: url,width:1,hidden:true} ], treeGrid: true, caption: Neighbourhood, ExpandColumn: name, ExpandColClick:true, autowidth: true }); }) }); }); /script div style=width:180px; table id=treeGrid /table -- --- You received this message because you are subscribed to the Google Groups web2py-users group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.