0

I'm using PHP to generate JSON for JQGrid. I've added another property to the PHP object that I'm JSON encoding:

$sql_array = preg_split('/LIMIT/', $sql);
$pass_sql = $sql_array[0];
$response->sql = $pass_sql;
<~SNIP~>
echo json_encode($response);

This parses fine on the client side and populates the jqGrid with JSON like this:

{"page":"1","total":28,"records":"685","sql":"SELECT * FROM fires ORDER BY id desc ","rows":[{"id":"3065","cell":["Southern","Lost Fire","National Forests in Mississippi","492","100","0000-00-00",null,null,null,null,null,null,null,null,null,null,null,"3065","2011-03-03 00:00:00"]},{"id":"3064","cell":["Southern","PineTree","East Central Area Dispatch Office","420","80","2011-03-02",null,null,null,null,null,null,null,null,null,null,null,"3064","2011-03-03 00:00:00"]},{"id":"3063","cell":["Southern","LILAC ROAD","Georgia Forestry Commission","100","100","2011-03-01",null,null,null,null,null,null,null,null,null //etc

I need to pull that sql param text out of the JSON reply and hide it in a DIV for later. Is this possible?

Jim Wharton
  • 1,375
  • 3
  • 18
  • 41

1 Answers1

0

The simplest way to send an additional information from the server to jqGrid is userdata (see this answer. If your JSON data will be like

{
    "page":"1",
    "total":28,
    "records":"685",
    "userdata":"SELECT * FROM fires ORDER BY id desc ",
    "rows":[
       ...
    ]
}

or

{
    "page":"1",
    "total":28,
    "records":"685",
    "userdata": {
        sql: "SELECT * FROM fires ORDER BY id desc "
    },
    "rows":[
       ...
    ]
}

The additional information will be saved inside of jqGrid and you can access of with $("#grid_id").jqGrid('getGridParam','userData').

Be careful in the case of userData. In the JSON data it must be userdata and in the getGridParam: 'userData'.

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798