Note that there are some explanatory texts on larger screens.

plurals
  1. POGetting and sorting from JSON on jqGrid
    text
    copied!<p>I'm new with jQuery and jqGrid and I'm getting two types of JSON content from another system with the following formats:</p> <p>Option #1</p> <pre><code>{ "@timestamp": "2012-03-27T16:19:26Z", "@toplevelentries": 40000, "items": [ { "@entryid": "1-B933790B1DC265ED8025725800728CC5", "@unid": "B933790B1DC265ED8025725800728CC5", "@noteid": "1E76E", "@position": "1", "@read": true, "@siblings": 40000, "$17": "Aaron, Adam", "InternetAddress": "consurgo@compleo.net", "OfficeCountry": "Namibia" }, { "@entryid": "2-9D93E80306A7AA88802572580072717A", "@unid": "9D93E80306A7AA88802572580072717A", "@noteid": "19376", "@position": "2", "@read": true, "@siblings": 40000, "$17": "Aaron, Dave", "InternetAddress": "gratia@incito.co.uk", "OfficeCountry": "Brazil" }, { "@entryid": "3-FAFA753960DB587A80257258007287CF", "@unid": "FAFA753960DB587A80257258007287CF", "@noteid": "1D842", "@position": "3", "@read": true, "@siblings": 40000, "$17": "Aaron, Donnie", "InternetAddress": "vociferor@nequities.net", "OfficeCountry": "Algeria" } ] } </code></pre> <p>Here the jqgrid I have is defined like this:</p> <pre><code>$().ready(function(){ jQuery("#list2").jqGrid({ url:'./xGrid2.xsp/peoplejson', datatype: "json", colNames:['#','InternetAddress','Name','OfficeCountry'], colModel:[ {name:'@position',index:'@position', width:50, sortable:true}, {name:'InternetAddress',index:'InternetAddress', width:200, sortable:true}, {name:'$17',index:'$17', width:200, sortable:true}, {name:'OfficeCountry',index:'OfficeCountry', width:200, sortable:true} ], jsonReader: { repeatitems: false, root: "items", id: "@position", records: "@toplevelentries", page:2, total:5 }, sortname: '@position', sortorder: "desc", height:500, rowNum:50, rowList:[50,100,150], caption:"JSON Example", pager: '#pager2' }); }); </code></pre> <p>I get the data but sorting and paging is not working.</p> <p>Option 2</p> <pre><code>[ { "@entryid": "1-B933790B1DC265ED8025725800728CC5", "@unid": "B933790B1DC265ED8025725800728CC5", "@noteid": "1E76E", "@position": "1", "@read": true, "@siblings": 40000, "@form": "Person", "$17": "Aaron, Adam", "InternetAddress": "consurgo@compleo.net", "OfficeCountry": "Namibia" }, { "@entryid": "2-9D93E80306A7AA88802572580072717A", "@unid": "9D93E80306A7AA88802572580072717A", "@noteid": "19376", "@position": "2", "@read": true, "@siblings": 40000, "@form": "Person", "$17": "Aaron, Dave", "InternetAddress": "gratia@incito.co.uk", "OfficeCountry": "Brazil" }, { "@entryid": "3-FAFA753960DB587A80257258007287CF", "@unid": "FAFA753960DB587A80257258007287CF", "@noteid": "1D842", "@position": "3", "@read": true, "@siblings": 40000, "@form": "Person", "$17": "Aaron, Donnie", "InternetAddress": "vociferor@nequities.net", "OfficeCountry": "Algeria" } ] </code></pre> <p>here the jqgrid I have is defined like this:</p> <pre><code>$().ready(function(){ jQuery("#list2").jqGrid({ url:'./xGrid4.xsp/peoplejson', datatype: "json", colNames:['InternetAddress','Name', 'OfficeCountry'], colModel:[ {name:'InternetAddress',index:'InternetAddress', width:200}, {name:'$17',index:'$17', width:200}, {name:'OfficeCountry',index:'OfficeCountry', width:200} ], jsonReader: { repeatitems: false, id: "InternetAddress", root: function (obj) { return obj; }, page: function (obj) { return 1; }, total: function (obj) { return 1; }, records: function (obj) { return obj.length; } }, caption:"JSON Example", height:500, sortable:true, rowNum:250, rowList:[250,500,750,1000], pager: '#pager2' }); }); </code></pre> <p>Again not sure if I'm defining correctly my jqrig object since here I don't have a root element on JSON.</p> <p>In both options sorting is not working and I cannot get populated correctly the total of records and pages on Pager element.</p> <p>Any help will be appreciated.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload