Hi,
I changed data format from JSON to XML and still the problem persist.
Table and headings are displayed but no data.I basically copied Mike's
code and did some tweaking. Ran the code but no data is displayed. I
checked Firebug, Console, Response and the data retrieved from the
server is:
<?xml version='1.0' encoding='utf-8'?><rows><page>1</page><total>5</
total><records>10</records><row id
= 063D268><cell>063D268</cell><cell>UGOT</cell><cell>IRMA</
cell><cell>VERSOZA</cell><cell>Languages
& Literature</cell><cell>5/14/1937</cell><cell></cell></row><row id =
031D163><cell>031D163</cell
><cell>MCINERNEY</cell><cell>MICHAEL</cell><cell>.</cell><cell>Physics</cell><cell>11/25/1948</cell>
<cell></cell></row></rows>
I also checked Firefox, Tools, Error Console and this was displayed:
Error: not well-formed
Source File:
http://127.0.0.1:8000/admin/default/edit/EMIS/views/employee%5Cmyview.html
Line: 49, Column: 106
Source Code:
<?xml version='1.0' encoding='utf-8'?><rows><page>1</
page><total.........
I checked the XML format of the result but found nothing wrong; sorry,
I am not an XML expert. The following is the code.
Controllers
---------------
def myview():
return dict()
def getdata():
response.headers["Content-Type"]="text/xml"
#start the XML data set
mystr = "<?xml version='1.0' encoding='utf-8'?><rows><page>1</
page><total>5</total><records>10</records>"
records=db().select(db.empmast.empno, db.empmast.lname,
db.empmast.fname, db.empmast.mname, db.empmast.costcenter,
db.empmast.bdate, db.empmast.sssno)
#build XML from dataset
for row in records:
mystr = mystr + '<row id = ' + str(row.empno) + '>'
mystr = mystr + '<cell>' + str(row.empno) + '</cell>'
mystr = mystr + '<cell>' + str(row.lname) + '</cell>'
mystr = mystr + '<cell>' + str(row.fname) + '</cell>'
mystr = mystr + '<cell>' + str(row.mname) + '</cell>'
mystr = mystr + '<cell>' + str(row.costcenter) + '</cell>'
mystr = mystr + '<cell>' + str(row.bdate) + '</cell>'
mystr = mystr + '<cell>' + str(row.sssno) + '</cell>'
mystr = mystr + '</row>'
mystr = mystr +'</rows>'
return mystr
Views
-----------
{{extend 'mylayout.html'}}
<!-- In head section we should include the style sheet for the grid --
>
<link href="{{=URL(r=request,c='static',f='jqGrid34/themes/sand/
grid.css')}}" rel="stylesheet" type="text/css" media="screen" />
<link href="{{=URL(r=request,c='static',f='jqGrid34/themes/
jqModal.css')}}" rel="stylesheet" type="text/css" media="screen
<!-- Of course we should load the jquery library -->
<script src="{{=URL(r=request,c='static',f='jqGrid34/jquery.js')}}"
type="text/javascript"></script>
<!-- and at end the jqGrid Java Script file -->
<script src="{{=URL(r=request,c='static',f='jqGrid34/
jquery.jqGrid.js')}}" type="text/javascript"></script>
<script src="{{=URL(r=request,c='static',f='jqGrid34/js/
jqModal.js')}}" type="text/javascript"></script>
<script src="{{=URL(r=request,c='static',f='jqGrid34/js/jqDnR.js')}}"
type="text/javascript"></script>
<script type="text/javascript">
// We use a document ready jquery function.
$(document).ready(function(){
$('#list2').jqGrid({
imgpath:'/{{=request.application}}/static/themes/sand/images',
url:'/EMIS/employee/getdata',
dataType:'xml',
mtype:'GET',
height:'100%',
// colNames parameter is a array in which we describe the names
// in the columns. This is the text that appear in the head of the
grid.
colNames:['Emp. No.','Last Name', 'First Name', 'Mid Name', 'Cost
Center', 'SSS No.'],
colModel:[
{name:'empno',index:'empno', width:80},
{name:'lname',index:'lname', width:160},
{name:'fname',index:'fname asc, lname', width:160},
{name:'mname',index:'mname', width:160},
{name:'costcenter',index:'costcenter', width:200},
{name:'sssno',index:'sssno', width:80}],
pager:jQuery('#pager2'),
rowNum:10,
rowList:[10,20,30],
sortname:'empno',
viewrecords:false,
sortorder:'asc',
caption:'Employees Personal File'
}).navGrid('#pager2', {edit:false, add:false, del:false});
});
</script>
</head>
<body>
<!-- the grid definition in html is a table tag with class 'scroll' --
>
<table id="list2" class="scroll"></table>
<!-- pager definition. class scroll tels that we want to use the same
theme as grid -->
<div id="pager2" class="scroll" style="text-align:center;"></div>
</body>
</html>
---------------------------------
I've seen some examples that define XMLreader, could this be what I
need to include in the code? I am not sure 'cuz it also says that if i
put "xml" in datatype option you don't need xmlreader. What do you
think? Thanks in advance.
Cheers,