Ich bin neu mit jQuery und jqGrid und ich bin immer zwei Arten von JSON Inhalt von einem anderen System mit den folgenden Formaten:Erste und Sortierung von JSON auf jqGrid
Option # 1
{
"@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": "[email protected]",
"OfficeCountry": "Namibia"
},
{
"@entryid": "2-9D93E80306A7AA88802572580072717A",
"@unid": "9D93E80306A7AA88802572580072717A",
"@noteid": "19376",
"@position": "2",
"@read": true,
"@siblings": 40000,
"$17": "Aaron, Dave",
"InternetAddress": "[email protected]",
"OfficeCountry": "Brazil"
},
{
"@entryid": "3-FAFA753960DB587A80257258007287CF",
"@unid": "FAFA753960DB587A80257258007287CF",
"@noteid": "1D842",
"@position": "3",
"@read": true,
"@siblings": 40000,
"$17": "Aaron, Donnie",
"InternetAddress": "[email protected]",
"OfficeCountry": "Algeria"
}
]
}
hier ist die jqGrid ich habe, ist wie folgt definiert:
$().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'
});
});
ich die Daten erhalten, aber das sortieren und Paging funktioniert nicht.
Option 2
[
{
"@entryid": "1-B933790B1DC265ED8025725800728CC5",
"@unid": "B933790B1DC265ED8025725800728CC5",
"@noteid": "1E76E",
"@position": "1",
"@read": true,
"@siblings": 40000,
"@form": "Person",
"$17": "Aaron, Adam",
"InternetAddress": "[email protected]",
"OfficeCountry": "Namibia"
},
{
"@entryid": "2-9D93E80306A7AA88802572580072717A",
"@unid": "9D93E80306A7AA88802572580072717A",
"@noteid": "19376",
"@position": "2",
"@read": true,
"@siblings": 40000,
"@form": "Person",
"$17": "Aaron, Dave",
"InternetAddress": "[email protected]",
"OfficeCountry": "Brazil"
},
{
"@entryid": "3-FAFA753960DB587A80257258007287CF",
"@unid": "FAFA753960DB587A80257258007287CF",
"@noteid": "1D842",
"@position": "3",
"@read": true,
"@siblings": 40000,
"@form": "Person",
"$17": "Aaron, Donnie",
"InternetAddress": "[email protected]",
"OfficeCountry": "Algeria"
}
]
hier die jqGrid ich habe, ist wie folgt definiert:
$().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'
});
});
wieder nicht sicher, ob ich da hier richtig mein jqrig Objekt definiere ich nicht eine habe Wurzelelement in JSON.
In beiden Optionen funktioniert die Sortierung nicht und ich kann die Gesamtzahl der Datensätze und Seiten auf dem Pager-Element nicht richtig ausfüllen.
Jede Hilfe wird geschätzt.
also was ist der Zweifel?Immer Code-Segment auswählen und Strg + K drücken, um den Code für bessere Lesbarkeit zu formatieren – Rajesh
Danke Rajesh Ich habe den Code in meinem Post bearbeitet. – PSolano