0

jqgrid can not work by set jsonReader ,repeatitems : false

firstly my jqgrid is getData by array

$(listvar).jqGrid({

}
$responce = new stdClass();

    $responce -> page = $page;

    $responce -> total = $total_pages;

    $responce -> records = $count;

    $responce -> rows[$num]['id'] = $row["id"];

$responce -> rows[$num]['cell']= array("fid" => $row['fid'], "fname" => $row['fname']);

echo json_encode($responce);

it works fine; ;but i want to by key value ; then i change code so jqgrid can get data by key value way; I reference

Using key/value pairs for jqGrid cell data

and

http://www.trirand.com/jqgridwiki/doku.php?id=wiki:retrieving_data#json_data


$(listvar).jqGrid({

enter code here`jsonReader : {

repeatitems : false,
   //others default value;

  },

}

mycode:

$responce = new stdClass();

    $responce -> page = $page;

    $responce -> total = $total_pages;

    $responce -> records = $count;

 $responce -> rows[$num]['id'] = $row["id"];

$responce -> rows[$num]['cell']= array("fid" => $row['fid'], "fname" => $row['fname']);

 echo json_encode($responce);

:web reponse ;

{"page":"1","total":1,"records":"1","rows":{"id":1,"cell":   [{"fid":"153","fname":"\u624b\u673a"}]}}

but jqgrid can not display data; what is the problem ?

Community
  • 1
  • 1
micro Java
  • 108
  • 1
  • 6

2 Answers2

1

The JSON data which you posted contains rows as object instead of array. It's your problem. You should change your server code so that it produces

{
    "page": "1",
    "total": 1,
    "records": "1",
    "rows": [
        {
            "id": 1,
            "cell": [
                {
                    "fid": "153",
                    "fname": "手机"
                }
            ]
        }
    ]
}

instead of

{
    "page": "1",
    "total": 1,
    "records": "1",
    "rows": {
        "id": 1,
        "cell": [
            {
                "fid": "153",
                "fname": "手机"
            }
        ]
    }
}

(see replacement of {} to [{}, ...,{}] for the value of rows)

Oleg
  • 220,925
  • 34
  • 403
  • 798
0
rows    an array that contains the actual data
  id    the unique id of the row
cell    an array that contains the data for a row

in http://www.trirand.com/jqgridwiki/doku.php?id=wiki:retrieving_data#json_data

so if u select key value way ; cell should not in the content json string;

$responce -> rows[$num]['id'] = $row["id"];

$responce -> rows[$num]['cell']= array("fid" => $row['fid'], "fname" => $row['fname']);
**result:** "rows":{"id":1,"cell":   [{"fid":"153","fname":"\u624b\u673a"}]}}

changed to be

$responce -> rows[$num]= array("id"=>"id","fid" => $row['fid'], "fname" => $row['fname']);

reponse json:** "rows":[{"id":null,"fid":"153","fname":"\u624b\u673a"

and num must from 0 because array in php must set begin at 0 , otherwise the result jsonString will be

-

  result:"rows":{"1":{"id":null,"fid":"153","fname":"\u624b\u673a"
phil
  • 620
  • 7
  • 12