JQuery JQGrid本地数据加载问题

时间:2010-06-15 21:03:48

标签: jquery jqgrid

我遇到以下代码的问题

<script type="text/javascript">
var mydata = [ {id:"1",name:"foo"},{id:"2",name:"bar"}  ];

jQuery(document).ready(function() {
jQuery("#lgrid").jqGrid({ data: mydata, 
                    datatype: "local", 
                    height: 150, 
                    width:600,
                    rowNum: 10, 
                    rowList: [10,20,30], 
                    colNames:['id','name'], 
                    colModel:[  {name:'id',index:'id', width:60, sorttype:"int"},
                                {name:'name',index:'name', width:60}], 
                    pager: "#pgrid", 
                    viewrecords: true, 
                    caption: "Contacts" });

});

</script>

而且身体......

<table id="lgrid"></table>
<div id="pgrid"></div>

使用此代码,我从不将数据显示到网格中。有人对这个问题有所了解吗? 感谢。

2 个答案:

答案 0 :(得分:0)

您的代码运行正常。你可以在这里发布完整的html ..查看输出屏幕截图link text 这是完整的HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<HTML>
<HEAD>
<META http-equiv="Content-Type" content="text/html; charset=utf-8">
<TITLE>test</TITLE>
<link type="text/css" href="lib/jquery/css/overcast/jquery-ui-1.8.2.custom.css" rel="stylesheet" />
<link rel="stylesheet" type="text/css" media="screen" href="lib/jqgrid/css/ui.jqgrid.css" />
<script type="text/javascript" src="lib/jquery/js/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="lib/jquery/js/jquery-ui-1.8.2.custom.min.js"></script>
<script src="lib/jqgrid/js/i18n/grid.locale-en.js" type="text/javascript"></script>
<script src="lib/jqgrid/js/jquery.jqGrid.js" type="text/javascript"></script>
<script type="text/javascript">
    var mydata = [ {id:"1",name:"foo"},{id:"2",name:"bar"}  ];

    jQuery(document).ready(function() {
    jQuery("#lgrid").jqGrid({ data: mydata, 
                        datatype: "local", 
                        height: 150, 
                        width:600,
                        rowNum: 10, 
                        rowList: [10,20,30], 
                        colNames:['id','name'], 
                        colModel:[  {name:'id',index:'id', width:60, sorttype:"int"},
                                    {name:'name',index:'name', width:60}], 
                        pager: "#pgrid", 
                        viewrecords: true, 
                        caption: "Contacts" });

    });

    </script>

</HEAD>
<BODY>
<table id="lgrid"></table>
<div id="pgrid"></div>

</BODY>
</HTML>

答案 1 :(得分:0)

尝试在jqGrid选项对象中设置localReader: { repeatitems: false }