I have a PHP script that extract valid GeoJSON data from a database. Now I would like to prepare a grid view of these data with jqgrid, but I can't figure out the proper jsonReader for the javascript code.
This is my GeoJSON output:
{"type":"FeatureCollection",
"total":0,
"page":1,
"records":117,
"features":[
{"geometry":{"type":"Point","coordinates":[12.3,41.70052]},
"type":"Feature",
"properties":{
"data":"2006-02-22",
"specie":"S. coeruleoalba",
"localita":"Ostia",
"provincia":"Roma"
},"id":0},
{"geometry":{
"type":"Point","coordinates":[15.26667,40.0502]},
"type":"Feature",
"properties":{
"data":"2006-03-01",
"specie":"S. coeruleoalba",
"localita":"Golfo di Salerno",
"provincia":"Salerno"
},"id":1},
{"geometry":{"type":"Point","coordinates":[14.88333,40.56692]},
"type":"Feature",
"properties":{
"data":"2006-03-03",
"specie":"S. coeruleoalba",
"localita":"Battipaglia",
"provincia":"Salerno"
},"id":2}
]}
Using this reader my grid shows the right number of rows (117) and pages, but empty cells
jsonReader : {
root: "features",
page: "page",
total: "total",
records: "records",
repeatitems: false,
cell: "properties",
id: "id"
}
Can someone help me to write a working reader? Thanks in advance
Your main error is that you try to use
cell: "properties"
, butcell
property will be ignored in case of usage ofrepeatitems: false
property.You should just use
and then define
jsonmap
property for every column. For example you can use the following column definition:As the result you will be able to read your JSON data to the following grid:
(see the demo here). In your JSON data I changed only
total
value from 0 to 1 because it has no sense to have thetotal
value less as thepage
value.