Forum

November 2nd, 2014
A A A
Avatar

Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

The forums are currently locked and only available for read only access
This topic is locked No permission to create posts
sp_Feed Topic RSS sp_TopicIcon
no data display with JQGrid and Turbogears
02/11/2009
15:46
Avatar
Ed Valentine
Member
Members
Forum Posts: 32
Member Since:
23/10/2009
sp_UserOfflineSmall Offline

I really like the possibilities of the widget as well as the documentation and support. We are using the Turbogears Python framework and I have found a developer using this combination.

I have the grid displayed in Firefox with firebug running.

I have been trying this and am close but the data does not display in the grid.

HTML:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>  
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

  <title>Sensadata 2.0</title>

<link rel="stylesheet" type="text/css" media="screen" href="css/redmond/jquery-ui-1.7.1.custom.css" />
<link rel="stylesheet" type="text/css" media="screen" href="css/ui.jqgrid.css" />

<script src="js/jquery-1.3.2.min.js" type="text/javascript"></script>
<script src="i18n/grid.locale-en.js" type="text/javascript"></script>
<script src="js/jquery.jqGrid.min.js" type="text/javascript"></script>
<script type="text/javascript">
jQuery(document).ready(function(){
        jQuery("#list").jqGrid({
        url:'grid1.html',
        datatype: 'json',
        jsonReader : {
          root: "rows",
          page: "page",
          total: "total",
          records: "records",
          repeatitems: true,
          cell: "cell",
          id: "id"
          },
        mtype: 'POST',
        colNames:['ID', 'Type','Item#','Proof#','Action'],
        colModel :[
                {name:'id', index:'id', width:55, sorttype:'int'},                  
                {name:'account', index:'account', width:80, align:'right', sorttype:'int'},
                {name:'item_nm', index:'item_nm', width:80, align:'right', sorttype:'int'},
                {name:'seq', index:'seq', width:80, align:'right'},
                {name:'action', index:'action', width:150, sortable:true} ],
        pager: jQuery('#pager'),
        rowNum:10,
        rowList:[10,20,30],
        sortname: 'id',
        sortorder: "desc",
        viewrecords: true, 
        caption: 'My first DATA grid' 
});
});
 </script>
 </head>
 <body>
         <table id="list" class="scroll"></table>
         <div id="pager" class="scroll" style="text-align:center;"></div>
       
 </body>
 </html>

This is the data sent from the controller of TG2:

23:06:59,946 DEBUG [sensadata.controllers.root]
{'records': '5', 'total': '1',
'rows': [{'cell': ['10009901', '0', '"11024438"', 'None'], 'id': '279976'},
{'cell': ['10009901', '0', '"11014912"', 'None'], 'id': '279977'},
{'cell': ['10009901', '4423', '"11024421"', 'None'], 'id': '279978'},
{'cell': ['10009901', '4425', '"11014910"', 'None'], 'id': '279979'},
 {'cell': ['12194001', '0', '"11083108"', '0'], 'id': '279975'}],
  'page': '1'}

Firebug shows this when the page is read the first time:

[Image Can Not Be Found](<!DOCTYPE html PUBLIC "-//W3C//DTD XHTM...3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\\n  jquery.j...id.min.js (line 10)

If I click the re-sort on the ID field, it will re-read the data, not issue an error and will not display the data.

Any suggestions??  Thanks.

04/11/2009
04:11
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

Hello,

I think you have a bad definition in jsonReader, which acts to this error. For this type of json response try this:

        jsonReader : {
          root: “rows”,
          page: “page”,
          total: “total”,
          records: “records”,
          repeatitems: true,
          cell: “cell”,
          id: “0″
          },

where id : 0 means that the id shoud be the first item in cell

More you can find here:

http://www.trirand.com/jqgridw.....eving_data

Regards

Tony

For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.

04/11/2009
13:30
Avatar
Ed Valentine
Member
Members
Forum Posts: 32
Member Since:
23/10/2009
sp_UserOfflineSmall Offline

Thanks. That stopped the error.

I still do not have the data displaying in the grid. It is not in the response. All I see is the <table id = 'list' .....> section where as I understand the data should be.

If I clink the sort arrows on the 'ID' column, I get a request to server and response in the Turbogears log and the message "Loading.." flashes, but no visable data.

Does this sound like something missing between the Trubogears controller and the templete / page generation?

Thanks for the help.

04/11/2009
13:57
Avatar
Rumen[Trirand]
Moderator
Members

Moderators
Forum Posts: 81
Member Since:
08/10/2009
sp_UserOfflineSmall Offline

From what I can tell, this could be the controller not sending the data in the correct JSON response format. Do you have control over that?

My suggestion is using a tool like Fiddler or FireBug to see what really gets sent back to the client (View Source in Browser will not work sinice the grid uses client-side rendering based on JSON)

Another thing to try - you can hook the loadError event of the grid and see if it gets fired and with what data.

Regards,

Rumen Stankov

Trirand ASP.NET WebForms & MVC components based on jQuery & ThemeRoller

http://www.trirand.net

04/11/2009
17:32
Avatar
Ed Valentine
Member
Members
Forum Posts: 32
Member Since:
23/10/2009
sp_UserOfflineSmall Offline

this is the log of the dist sent from the controller :

23:06:59,946 DEBUG [sensadata.controllers.root]
{'records': '5', 'total': '1',
'rows': [{'cell': ['10009901', '0', '"11024438"', 'None'], 'id': '279976'},
{'cell': ['10009901', '0', '"11014912"', 'None'], 'id': '279977'},
{'cell': ['10009901', '4423', '"11024421"', 'None'], 'id': '279978'},
{'cell': ['10009901', '4425', '"11014910"', 'None'], 'id': '279979'},
 {'cell': ['12194001', '0', '"11083108"', '0'], 'id': '279975'}],
  'page': '1'}

The sample has ", this has ' . Is that a problem?

04/11/2009
23:01
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

Hello,

I think yes. In this case you should escape it by example:

23:06:59,946 DEBUG [sensadata.controllers.root]
{'records': '5', 'total': '1',
'rows': [{'cell': ['10009901', '0', '\\"11024438\\"', 'None'], 'id': '279976'},

...

Regards

Tony

For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.

11/11/2009
22:15
Avatar
Ed Valentine
Member
Members
Forum Posts: 32
Member Since:
23/10/2009
sp_UserOfflineSmall Offline

Hope this does not sound really dumb.

All of the response viewers are showing the full page without <table id="list" class="scroll"></table>
being replaced with data.

Is the page supposed to load and then send the data request and load the data? I am thinking that Turbogears as I have it know is passing the page and the json data to the stack in TG2 and TG2 expects to do the replacement in the page.

If jqgrid is to do the replacement of  <table id="list" class="scroll"></table> with the data then I need to change my TG2 code.

Thanks for your help. Tell me when I need to send payment for your time. Smile

12/11/2009
10:37
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

Hello,

No jqGrid does not replace the table. It just add some additinal elements below and above it, but table stay the same. If you have FireBug you can easy see the the table is still here, and after that we populate the table with data.

I do not known what TurboGear do, so I can not  give you some point to where you can start.

Best Regards

Tony

For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.

15/11/2009
21:36
Avatar
Ed Valentine
Member
Members
Forum Posts: 32
Member Since:
23/10/2009
sp_UserOfflineSmall Offline

I must be doing something dumb. This is the exact return sent to the client after the form is displayed with no data.I thought this to be the correct format for the response and the Javascript is to read this and insert into the grid.

Any suggestions?Confused

Does the content-type need to be "json"?

HTTP/1.0 200 OK
Server: PasteWSGIServer/0.5 Python/2.5.4
Date: Mon, 16 Nov 2009 03:18:45 GMT
Pragma: no-cache
Cache-Control: no-cache
Content-Type: text/html; charset=utf-8
Content-Length: 260

{page:"1",total:"1",records:"5", rows:[{"279976","10009901","0","None","None"},{"279977","10009901","0","11014912","None"},{"279978","10009901","4423","11024421","None"},{"279979","10009901","4425","11014910","None"},{"279975","12194001","0","11083108","1"},]}

17/11/2009
02:24
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

Hello,

Any error in the console.

Also in this case you should set cell to empty string in jsonReader: See here:

http://www.trirand.com/jqgridw.....eving_data

jsonReader : {
          root: “rows”,
          page: “page”,
          total: “total”,
          records: “records”,
          repeatitems: true,
          cell: “”,
          id: “0″
          },

Save the response to a file and try to load via data string - I mean  - set datatype to jsonstring and put a part from the response in string an see the result.

Regards
Tony

For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.

17/11/2009
12:41
Avatar
Ed Valentine
Member
Members
Forum Posts: 32
Member Since:
23/10/2009
sp_UserOfflineSmall Offline

Is there a way to get the jqgrid.js code with the line feed/ carage returns? now I am getting the error 'invalid object initualizer' and I can not determine where in the code.

If I set the datatype = 'jsonstring' in the html, there is no request sent back to the host.

17/11/2009
15:12
Avatar
notnow
Guest
Guests

I got the table to show by using 'GET' instead of post, but am  having css problems.Laugh

17/11/2009
16:44
Avatar
notnow
Guest
Guests

As far as I can tell, the controller, html, and scripts from your first post looks about the same as my application.  In fact I emulated your setup with my application and just changed to 'get' and it worked.  Can you help with css when you get yours displaying.  I am getting a  "404 Not Found" when I click edit in firebug in the css section.Confused

18/11/2009
10:31
Avatar
notnow
Guest
Guests

Just discovered css is working in ie, but getting message:

[Exception... "Component returned failure code: 0x80040111 (NS_ERROR_NOT_AVAILABLE) [nsIChannel.contentType]" nsresult: "0x80040111 (NS_ERROR_NOT_AVAILABLE)" location: "JS frame :: file:///C:/Program%20Files/Mozilla%20Firefox/components/FeedProcessor.js :: FP_onStartRequest :: line 1440" data: no] from firefox

jquery-1.3.2

firefox 3.5.5

This may not be correct thread.  I am trying to thread for turbogears folks, but I don't think this is unique to turbogears.

18/11/2009
13:50
Avatar
Ed Valentine
Member
Members
Forum Posts: 32
Member Since:
23/10/2009
sp_UserOfflineSmall Offline

I am glad someone has been able to get this to work. I have upgraded to grid3.6, gone to the Lightness UI, and switched to the /src .js code.

The response is:

HTTP/1.0 200 OK
Server: PasteWSGIServer/0.5 Python/2.5.4
Date: Mon, 16 Nov 2009 03:18:45 GMT
Pragma: no-cache
Cache-Control: no-cache
Content-Type: text/html; charset=utf-8
Content-Length: 260

{page:”1″,total:”1″,records:”5″, rows:[{"279976","10009901","0","None","None"}{"279977","10009901","0","11014912","None"},{"279978","10009901","4423","11024421","None"},{"279979","10009901","4425","11014910","None"},{"279975","12194001","0","11083108","1"},]}

With NO cr/lf in the data, one long string.

I am getting an error "invalid object initializer"  at line 59 of grid.base.js

parse : function(jsonString) {
        var js = jsonString, msg;
        if (js.substr(0,9) == "while(1);") { js = js.substr(9); }
        if (js.substr(0,2) == "/*") { js = js.substr(2,js.length-4); }
        if(!js) { js = "{}"; }
        ($.jgrid.useJSON===true && typeof (JSON) === 'object' && typeof (JSON.parse) === 'function')
            ? msg = JSON.parse(js)
            : msg = eval('(' + js + ')');                                  <<<<< THIS LINE
        return  msg.hasOwnProperty('d') ? msg.d : msg;
    },
    empty : function () {
        while ( this.firstChild ) this.removeChild( this.firstChild );
    },

Is this indicate the response is not formatted correctly? Incorrect quotes????

In all of this effort, I have identified that the location of files and sub-directories is most important. The CSS section includes and calls files based on the installation instructions. I would check all of the files and locations if you are getting the 404 error.

Thanks for all of the help.

18/11/2009
14:22
Avatar
Ed Valentine
Member
Members
Forum Posts: 32
Member Since:
23/10/2009
sp_UserOfflineSmall Offline

notnow said:

As far as I can tell, the controller, html, and scripts from your first post looks about the same as my application.  In fact I emulated your setup with my application and just changed to 'get' and it worked.  Can you help with css when you get yours displaying.  I am getting a  “404 Not Found” when I click edit in firebug in the css section.Confused


How are you generating your response? Are you using a "return dict( page=page, ........) or some other way??  Can you send the raw response?

I think this is where I am having my issues?

Thanks.

18/11/2009
16:38
Avatar
notnow
Guest
Guests

I'm using different data but this is what I copied from response

{"records": "3", "total": "1",
 "rows": [{"cell": ["Bolivar Elementary", "445 Nuckolls Road",
 "Bolivar"
, "TN", "38008", "Pre k - 5"], "id": "1"},
 {"cell": ["Bolivar Middle School", "915 Pruitt St",
 "Bolivar"
, "TN", "38008", "6 - 8"], "id": "2"},
 {"cell": ["Bolivar Central Highschool", "313 Harris St.",
 "Bolivar"
, "TN", "38008", "9 - 12"], "id": "3"}], "page": "1"}

This is with regular json. This looks close to what you showed on your first post.

return dict(page=str(page),total=str(totPages), records=str(records),rows=rows)
18/11/2009
19:13
Avatar
Ed Valentine
Member
Members
Forum Posts: 32
Member Since:
23/10/2009
sp_UserOfflineSmall Offline

How are you returning the html page the first time and just the data after that? Have you split into two methods, one with @expose (url page name) and the second with @expose("json")?

18/11/2009
23:57
Avatar
andrewwatts
Member
Members
Forum Posts: 10
Member Since:
06/10/2009
sp_UserOfflineSmall Offline

Hello Ed, we spoke in the TG forum about this issue and I just stumbled on your posts here.

Now that I've seen your code I can say a bit more and I believe you need to go back and double check all your script and css paths.  If you followed the instructions at /jqgridwiki/doku.php?id=wiki:jquery_ui_intro you'll notice that you are missing the jquery ui script file and also that your locale file is in the wrong place (at least according to the installation).

I copied and pasted the code from your first post of this thread and get the error you describe. I fixed the js paths for my environment and the errors went away and the grid successfully renders.  Here is a diff of what I changed (lines that begin with '-' are your original code, lines that begin with '+' are how I changed them)

   <title>Sensadata 2.0</title>
-<link rel=”stylesheet” type=”text/css” media=”screen” href=”css/redmond/jquery-ui-1.7.1.custom.css” />
+<link rel=”stylesheet” type=”text/css” media=”screen” href=”css/jquery-ui-1.7.2.custom.css” />
 <link rel=”stylesheet” type=”text/css” media=”screen” href=”css/ui.jqgrid.css” />
 
 <script src=”js/jquery-1.3.2.min.js” type=”text/javascript”></script>
-<script src=”i18n/grid.locale-en.js” type=”text/javascript”></script>
+<script type=”text/javascript” src=”/js/jquery-ui-1.7.2.custom.min.js”></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”>
 jQuery(document).ready(function(){

Also, if it helps, here are the TG controller methods I used to test with.

    @expose('ui.templates.grid1')
    def grid(self, *args, **kwargs):
        return dict()
   
    @expose('json')
    def grid1(self, *args, **kwargs):
       
        a_dict = {'records': '5',
                  'total': '1',
                  'rows': [{'cell': ['10009901', '0', '"11024438"', 'None'], 'id': '279976'},
                           {'cell': ['10009901', '0', '"11014912"', 'None'], 'id': '279977'},
                           {'cell': ['10009901', '4423', '"11024421"', 'None'], 'id': '279978'},
                           {'cell': ['10009901', '4425', '"11014910"', 'None'], 'id': '279979'},
                           {'cell': ['12194001', '0', '"11083108"', '0'], 'id': '279975'}],
                  'page': '1'}
       
        return a_dict

Again, simply updating the javascript src includes for my environment successfully rendered a chart using the rest of your code.

Hope this helps.

- Andrew

19/11/2009
12:39
Avatar
notnow
Guest
Guests

I sort of wondered about those paths, but figured that was where you had the files.

Ed
Now we need to get a tw developer to develope jqquery as a widget with the tw2 core. With the documentation available it might not be that difficult for them. I may play with it, but I am not that strong of a developer, I'm just an accountant trying to write a school accounting application.

This topic is locked No permission to create posts
Forum Timezone: Europe/Sofia

Most Users Ever Online: 715

Currently Online:
181 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.com

Moderators: tony: 7721, Rumen[Trirand]: 81

Administrators: admin: 66

Comments are closed.
Privacy Policy   Terms and Conditions   Contact Information