Jqgrid不会用json数据填充表


jqgrid will not populate the table with json data

我一直在寻找这个问题的答案,但一直没有找到一个。我目前正在从一个mssql数据库中获取数据,一切似乎都很好地填充在php端,但这里是代码无论如何

$responce->total = $total_pages;
$responce->page = $page;
$responce->records = $count;
$i=0;
while($row = sqlsrv_fetch_array($result,SQLSRV_FETCH_ASSOC)) {
    $responce->rows[$i]['id']=$row[Cell1];            
    $responce->rows[$i]['cell']=array($row[Cell1],$row[Cell2],$row[Cell3]);
    $i++;
}
echo $json_encode($responce);

我的json文件是这样输出的:

{"total":"1","page":"1","records":"1","rows":[{"id":"1","cell":["1","2","3"]}]}

最后我的HTML是这样的:

<link rel="stylesheet" type="text/css" media="screen" href="css/south-street/jquery-ui-1.10.3.custom.css" />
<link rel="stylesheet" type="text/css" media="screen" href="css/ui.jqgrid.css" />
<link href="css/ui.multiselect.css" />
<script src="js/jquery.js" type="text/javascript"></script>
<script src="js/jquery-1.9.0.min.js" type="text/javascript"></script>
<script src="js/jquery.layout.js" type="text/javascript"></script>
<script src="js/i18n/grid.locale-en.js" type="text/javascript"></script>
<script src="js/jquery.jqGrid.min.js" type="text/javascript"></script>
<script src="js/ui.multiselect.js" type="text/javascript"></script>
<script type="text/javascript">
jQuery(document).ready(function () {
    $("#list").jqGrid({
        url: "retrieve.php",
        datatype: "json",
        mtype: "POST",
        colNames: ["Cell1", "Cell2", "Cell3"],
        colModel: [
            { name: "Cell1", width:55 , index:'Cell1' },
            { name: "Cell2", width: 90, index:'Cell2' },
            { name: "Cell3", width: 80, index:'Cell3' },
        ],
        jsonReader: { repeatitems: false },
        pager: "#pager",
        rowNum: 10,
        rowList: [10, 20, 30],
        scroll:1,
        sortname: Cell1",
        sortorder: "asc",
        sortable:true,
        viewrecords: true,
        gridview: true,
        ignoreCase:true,
        autowidth:true,
        ondblClickRow: function (id) {
            $(this).jqGrid('viewGridRow', id, { caption: "Server Information" });
        }
    });
});
</script>

如果有人能帮我弄清楚为什么我的网格不能正确填充,我真的很感激!

代码中的主要错误如下:

    你应该修复语法错误sortname: Cell1"sortname: "Cell1"
  • 删除jsonReader: { repeatitems: false },这是错误的格式,你使用。
  • 删除第二个版本的jQuery。jquery.jsjquery-1.9.0.min.js均可。

可能是你的JS文件有冲突。

<script src="js/jquery.js" type="text/javascript"></script>
<script src="js/jquery-1.9.0.min.js" type="text/javascript"></script> 

你应该只使用一个JS,而不是使用两个jquery文件。

<script src="js/jquery-1.9.0.min.js" type="text/javascript"></script> 
<script src="js/i18n/grid.locale-en.js" type="text/javascript"></script>
<script src="js/jquery.jqGrid.min.js" type="text/javascript"></script>
<script src="js/jquery.layout.js" type="text/javascript"></script>
<script src="js/ui.multiselect.js" type="text/javascript"></script>

请从colModel中删除","

colModel: [
            { name: "Cell1", width:55 , index:'Cell1' },
            { name: "Cell2", width: 90, index:'Cell2' },
            { name: "Cell3", width: 80, index:'Cell3' },
        ],

colModel: [
            { name: "Cell1", width:55 , index:'Cell1' },
            { name: "Cell2", width: 90, index:'Cell2' },
            { name: "Cell3", width: 80, index:'Cell3' }
        ],

我认为它解决了你所有的问题。