将JSON字符串中的其他参数发送到jqGrid

时间:2011-03-03 22:32:58

标签: php json jqgrid

我正在使用PHP为JQGrid生成JSON。我已经为PHP对象添加了另一个属性,我是JSON编码:

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

这在客户端解析并使用JSON填充jqGrid:

{"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

我需要从JSON回复中提取sql param文本并将其隐藏在DIV中以供日后使用。这可能吗?

1 个答案:

答案 0 :(得分:0)

从服务器向jqGrid发送附加信息的最简单方法是userdata(请参阅this answer。如果您的JSON数据类似

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

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

其他信息将保存在jqGrid中,您可以使用$("#grid_id").jqGrid('getGridParam','userData')访问。

userData的情况要小心。在JSON数据中,它必须是userdatagetGridParam:'userData'。