Forum


17:51

25/11/2011

Problem: blank grid and multiple CSS errors with jquery-ui-1.8.16.custom.css" and ui.jqgrid.css.
Dear Tony,
I have set up the css and js directories as described in the Installation section of the documentation. My server produces the following JSON:
{"ROWS":[["1","GNN","","","","UK","editorial@mvn.org.uk","","",""],["2","The Courier","","","","OZ","ian@courier.net.au","","",""]],"PAGE":"1","RECORDS":"2","TOTAL":"1.0"}
However, I get a grid with no data.
I am wondering if the problem might not be the CSS. I am using jQuery 1.6.2, jQuery-UI 1.8.16 and jqGrid 4.1.0. I get a huge list of errors in the CSS, according to Opera Dragonfly:
My HTML and JS is:
<link rel="stylesheet" type="text/css" media="screen" href="css/ui-lightness/jquery-ui-1.8.16.custom.css" />
<link rel="stylesheet" type="text/css" media="screen" href="css/ui.jqgrid.css" />
<style type="tex/css">
html, body {
margin: 0;
padding: 0;
font-size: 75%;
}
</style>
<script src="js/jquery-1.6.2.min.js" type="text/javascript"></script>
<script src="js/i18n/grid.locale-en.js" type="text/javascript"></script>
<script src="js/jquery.jqGrid.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function(){
$("#list").jqGrid({
url:'contactInfo.cfc?method=contacts',
datatype: 'json',
mtype: 'GET',
colNames:['Name','Street','City','ZIP','Country','Email','Contact Title','Contact First Name','Contact Second Name'],
colModel :[
{name:'name', index:'name', width:55},
{name:'street', index:'street', width:90},
{name:'city', index:'city', width:80, align:'right'},
{name:'zip', index:'zip', width:80, align:'right'},
{name:'country', index:'country', width:50, align:'right'},
{name:'email', index:'email', width:50, sortable:false},
{name:'contactTitle', index:'contactTitle', width:55},
{name:'contactFirstName', index:'contactFirstName', width:55},
{name:'contactSecondName', index:'contactSecondName', width:55}
],
pager: '#pager',
rowNum:10,
rowList:[10,20,30],
sortname: 'sidx',
sortorder: 'sord',
viewrecords: true,
gridview: true,
caption: 'Contact Information',
jsonReader: {
root: "rows",
page: "page",
total: "total",
records: "records",
cell: "",
id: "0"
}
});
});
</script>
Do you have any idea what the problem might be?
Thanks for your help.
Paul
18:47

10/08/2009

Hello Paul,
you should don't forget, that JSON, like JavaScript, is case-sensitive. So you have to chanage the JSON data produced on the server to
"rows": [
["1","GNN","","","","UK","editorial@mvn.org.uk","","",""],
["2","The Courier","","","","OZ","ian@courier.net.au","","",""]
],
"page": "1",
"records": "2",
"total": "1.0"
}
and use jsonReader: {cell: "", id: "0"} (it's enough to specify only the properties of jsonReader which you want overwrite, you don't need specify any default properties) or you can don't make any changes in the server code, but change the properties of the jsonReader to
root: "ROWS",
page: "PAGE",
total: "TOTAL",
records: "RECORDS",
cell: "",
id: "0"
}
Best regards
Oleg
19:56

25/11/2011

Thanks very much, Oleg. The problem was that ColdFusion turned the small-case names in my code into capitals: I didn't look closely enough at the JSON it was producing. I have also changed the server-side code so that it has the correct brackets. It is now producing the following JSON:
{"total": "1", "page": "1", "records": "2", "rows": [{"1", "GNN", "", "", "", "UK", "editorial@mvn.org.uk", "", "", ""},{"2", "The Courier", "", "", "", "OZ", "ian@courier.net.au", "", "", ""}]}
Unfortunately there seems to be another problem, though: I still get the same CSS errors, and the grid still has no data. Are these versions of jQuery, jQueryUI and jqGrid compatible with each other?
Thanks again for your help.
With best wishes,
Paul
15:08

10/08/2009

Hello Paul,
how you can see from the demo your original code with fixed case in the jsonReader and with your original JSON data can do be read. (I added only height: "auto" parameter for better look). So you should look at some another place for the error.
For example you can verify which value has Content-Type part of the HTTP header which produce your server.
In any way I recommend you include loadError callback in your code. See my old answer here for more details.
Best regards
Oleg
18:13

25/11/2011

Dear Oleg,
Thanks again for your help.
Unfortunately I am very confused. The JSON is coming from a ColdFusion CFC, not a CFM page, so it doesn't have anything added or taken away. In any case, I have checked it using Dragonfly and Firebug and it corresponds exactly to the format shown in the documentation. I don't understand why it can be read by your page but not by mine.
I installed the loadError function which you mentioned: this gave the cryptic error "; expected", which is apparently a parsing error. So instead of creating the JSON as a string and then outputting it from ColdFusion as plain text, I am outputting it as JSON generated by ColdFusion.
This means that instead of:
{"total": "1″, "page": "1″, "records": "2″, "rows": [{"1", "GNN", "", "", "", "UK", "editorial@mvn.org.uk", "", "", ""},{"2", "The Courier", "", "", "", "OZ", "ian@courier.net.au", "", "", ""}]}
I am sending:
"{"total": "1″, "page": "1″, "records": "2″, "rows": [{"1", "GNN", "", "", "", "UK", "editorial@mvn.org.uk", "", "", ""},{"2", "The Courier", "", "", "", "OZ", "ian@courier.net.au", "", "", ""}]}"
This gives no parsing errors.
I am extremely confused and very frustrated. The first version works (for you) and seems to be correct. But it gives a parsing error. The second version doesn't produce a parsing error. Neither version actually puts any data in the grid.
I have been working on this single problem for an entire week and am absolutely desperate for a solution. Any help or input would be very much appreciated.
Thanks again for your help.
With best wishes,
Paul
P.S. Here is my entire HTML page with the jqGrid script:
<link rel="stylesheet" type="text/css" media="screen" href="css/ui-lightness/jquery-ui-1.8.16.custom.css" />
<link rel="stylesheet" type="text/css" media="screen" href="css/ui.jqgrid.css" />
<style type="tex/css">
html, body {
margin: 0;
padding: 0;
font-size: 75%;
}
</style>
<script src="js/jquery-1.6.2.min.js" type="text/javascript"></script>
<script src="js/i18n/grid.locale-en.js" type="text/javascript"></script>
<script src="js/jquery.jqGrid.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function(){
$("#list").jqGrid({
url:'contactInfo.cfc?method=contacts',
datatype: 'json',
colNames:['Name','Street','City','ZIP','Country','Email','Contact Title','Contact First Name','Contact Second Name'],
colModel :[
{name:'Name', index:'name', width:55},
{name:'Street', index:'street', width:90},
{name:'City', index:'city', width:80, align:'right'},
{name:'ZIP', index:'ZIP', width:80, align:'right'},
{name:'Country', index:'country', width:50, align:'right'},
{name:'Email', index:'email', width:50},
{name:'ContactTitle', index:'contactTitle', width:55},
{name:'ContactFirstName', index:'contactFirstName', width:55},
{name:'ContactSecondName', index:'contactSecondName', width:55}
],
pager: '#pager',
rowNum:10,
rowList:[10,20,30],
sortname: 'name',
sortorder: 'asc',
viewrecords: true,
caption: 'Contact Information',
loadComplete: function () {
alert("OK");
},
loadError: function (jqXHR, textStatus, errorThrown) {
alert('HTTP status code: ' + jqXHR.status + '\n' +
'textStatus: ' + textStatus + '\n' +
'errorThrown: ' + errorThrown);
alert('HTTP message body (jqXHR.responseText): ' + '\n' + jqXHR.responseText);
},
jsonReader: {
repeatitems: true,
cell: '',
id: '0'
}
})
});
</script>
</head>
<body>
<table id="list"></table>
<div id="pager"></div>
</body>
</html>
And here is my ColdFusion CFC, which is generating the JSON:
<cfcomponent hint="Sends contact information in text">
<cffunction name="contacts"
hint="Shows all contacts"
access="remote"
returnformat="plain">
<cfargument name="page"
default="1"
hint="Page we are on">
<cfargument name="rows"
default="10"
hint="Number of rows to show at once">
<cfargument name="sord"
default="name"
required="no"
type="string">
<cfargument name="sidx"
default="asc"
required="no"
type="string">
<cfstoredproc
procedure="showAllContacts"
datasource="crystallake">
<cfprocparam
value="name"
cfsqltype="cf_sql_varchar">
<cfprocparam
value="asc"
cfsqltype="cf_sql_varchar">
<cfprocresult name="showAllContacts">
</cfstoredproc>
<!---Generate the JSON packet based on the showAllContacts query--->
<!---Find start point--->
<cfset start = ((arguments.page - 1) * arguments.rows + 1)>
<!---Find end point--->
<cfset end = (start - 1) + arguments.rows>
<!---Create array to hold values retrieved from database--->
<!---<cfset dbValues = ArrayNew(1)>--->
<cfset dbValues = "">
<!---set up counter - cannot use currentrow, as this is the row number in the query, not in the loop--->
<cfset i = 1>
<!---Loop through query from start to end--->
<cfloop query="showAllContacts" startRow=#start# endRow=#end#>
<cfset dbValues = dbValues & ',{"#id#", "#name#", "#street#", "#city#", "#zip#", "#country#", "#email#", "#contactTitle#", "#contactFirstName#", "#contactSecondName#"}'>
<cfset i = I + 1>
</cfloop>
<!---Remove leading comma from dbValues--->
<cfset dbValues = right(dbvalues, len(dbValues) - 1)>
<!---Add square brackets round dbvalues--->
<cfset dbValues = "[" & dbValues & "]">
<!---Calculate total number of pages--->
<cfset totalPages = ceiling(showAllContacts.recordcount/arguments.rows)>
<!---Add dbValues to the rest of the JSON--->
<cfset strReturn = '{"total": "#totalPages#", "page": "#arguments.page#", "records": "#showAllContacts.recordcount#", "rows": #dbValues#}'>
<cfreturn strReturn>
</cffunction>
</cfcomponent>
19:17

10/08/2009

Hello Paul,
You wrote, that you used Firebug to examine the server response. Which value has Content-Type header of the server response? Correct Content-Type for json data is "application/json". The parsing error "; expected" look like jQuery.ajax interpret the server response as datatype: "script". So I think it's you main problem.
Moreover, it can be the problem of the editor of the forum, but the HTML page which you posted contains no header information ("<!DOCTYPE html …", "<html>" and "head"). You should verify that the first lines of the page exists. Moreover I recommend you always verify your page in the http://validator.w3.org. For example, you can see here that my demo which I posted you before contain correct XHTML 1.0 Strict code. Look at here for more code examples.
You can verify any JSON data here and any JavaScript code here. If you for example get the source code of my demo cut the code between //<![CDATA[ and //]]> lines, shift the code in any text editor lefts so that /*global $ */ will be in the first column you can post the code in the http://www.jslint.com/ and see no errors and warnings. This precedures can improve quality of your code and shows some errors which you don't see yourself.
I still think that your main problem is wrong Content-Type HTTP header which produce your server code.
Best regrads
Oleg
P.S. By the way you can try to use jQuery 1.4.4 for one test only. Old versions of jQuery don't use information from Content-Type and just decode the server response based on the dataType parameter of jQuery.ajax. If your data will be read correctly by jQuery 1.4.4 it will be one more sign that your problem is wrong Content-Type.
20:37

25/11/2011

Dear Oleg,
Once again, thanks very much indeed for your help.
I have set the MIME type in IIS to application/JSON, and have included a tag into my ColdFusion CFC to make absolutely certain that it is sending JSON. I now get the following in Dragonfly:
HTTP/1.1 200 OK
Transfer-Encoding: chunked
Content-Type: application/json
Server: Microsoft-IIS/7.5
X-Powered-By: ASP.NET
Date: Sun, 27 Nov 2011 18:22:07 GMT
{"total": "1″, "page": "1″, "records": "2″, "rows": [{"1", "GNN", "", "", "", "UK", "editorial@mvn.org.uk", "", "", ""},{"2", "The Courier", "", "", "", "OZ", "ian@courier.net.au", "", "", ""}]}
With Firebug I can only see the header of the page which contains the JavaScript (the first page above) not the CFC which produces the JSON (the second page above). However, as you can see, Dragonfly seems to think that this is OK.
I checked my JSON at the site you mentioned. It gives me the parsing error shown below. However, the JSON is OK according to the Wiki (wiki_retrieving_data). JSLint produced no errors apart from spacing errors which I have corrected. I am using WebStorm, which also can't find any errors in my JavaScript.
I am really at a loss. Do you have any other suggestions?
Thanks again for all your help.
With best wishes,
Paul
[Image Can Not Be Found]
21:40

10/08/2009

Hello Paul,
the JSON data which you posted in your first question and which I used in my answer (and my demo too) was correct JSON data. The ROWS property was array of arrays ({"ROWS":[["1",...],["2", ...]], ...). You last data contains {} instead of [] which must be used for arrays.
The items like
must be replaced to
Then you will have correct JSON data. The JSON rules are so simple that full description you can find on the page.
Probably you should go back to you original code, use jsonReader which I suggested in my fisrt answer and verify that you have 'Content-Type: application/json' as HTTP header (like in you last post).
After all the steps your program have to work.
Best regards
Oleg
22:24

25/11/2011

Dear Oleg,
I have changed this, and it works!! Thanks very much for your help.
I should have remembered that a JS array uses square brackets. The reason why I changed the brackets from '[' to '{' is because this is what is shown in the documentation:
http://www.trirand.com/jqgridw.....eving_data
>>It is possible to set the cell element to an empty string. And, it is possible to set the id as number. Here is an example of these possibilities:
jQuery("#gridid").jqGrid({
...
jsonReader : {
root:"invdata",
page: "currpage",
total: "totalpages",
records: "totalrecords",
cell: "",
id: "0"
},
...
});
>>In this case the id is the first element from the row data
{
"totalpages" : "xxx",
"currpage" : "yyy",
"totalrecords" : "zzz",
"invdata" : [
{"1","cell11", "cell12", "cell13"},
{"2",,"cell21", "cell22", "cell23"},
...
]
}
ColdFusion produced originally gave me '[': I refactored the code to create the JSON from scratch so I could have '{'. It seems that ColdFusion was right after all.
Is this a mistake in the documentation, or have I misunderstood something?
Thanks again for your help!
With best wishes,
Paul
22:47

10/08/2009

Hello Paul,
I am glad to read that your program is work now.
You are right, there are a mistake in the documentation of jqGrid. Fortunately the documentation is wiki-documentation and everybody can change it. So I fixed the corresponding place in the documentation just now.
Good luck
Oleg
Most Users Ever Online: 715
Currently Online:
93 Guest(s)
Currently Browsing this Page:
1 Guest(s)
Top Posters:
OlegK: 1255
markw65: 179
kobruleht: 144
phicarre: 132
YamilBracho: 124
Renso: 118
Member Stats:
Guest Posters: 447
Members: 11373
Moderators: 2
Admins: 1
Forum Stats:
Groups: 1
Forums: 8
Topics: 10592
Posts: 31289
Newest Members:
, razia, Prankie, psky, praveen neelam, greg.valainis@pa-tech.comModerators: tony: 7721, Rumen[Trirand]: 81
Administrators: admin: 66