2014-02-10 43 views
1

我已经写了这段代码。JqGrid没有显示任何数据

<html> 
    <head> 
    <title>My First JqGrid</title> 
    <script src="js/jquery-1.8.2.min.js"></script> 
    <link rel="stylesheet" type="text/css" media="screen" href="css/jquery-ui-1.7.2.custom.css" /> 
    <script src="js/jquery.jqGrid.min.js"></script> 
    <link rel="stylesheet" type="text/css" media="screen" href="css/ui.jqgrid.css" /> 

    <script type="text/javascript"> 

    $(document).ready(function(){ 

    var obj; 
    var mydata='[{"id":"1"},{"id":"2"}]'; 
    obj = JSON.parse(mydata); 

    $("#list").jqGrid({ 
     dataType: 'json', 
     data :obj, 
     colNames: ['id'], 
     colModel: [ 
         { name: 'id', index: 'id', width: 120, sortable: true } 

      ], 
     autowidth: true, 
     viewrecords: true 
    }); 

    }); 
    </script> 

</head> 
<body> 
    <table id="list"> 
<tr> 
    <td></td> 
</tr> 
    </table> 
</body> 

,一切工作正常。但我无法看到数据。可能是什么问题?

在此先感谢。

回答

0

如果您使用的是本地数据(如上面的本地数组),那么您需要将datatype选项更改为local。另外,请记住,这个东西是区分大小写的,所以在你的情况下,你实际上有dataType,它是datatype

datatype: 'local' 

另外,由于使用的是本地数据(数组)所有需要做的是通过阵列的jqGrid,你需要解析数组作为JSON像您的上方。

从jqGrid的文档:

数据:

An array that stores the local data passed to the grid. You can directly point to this variable in case you want to load an array data.

数据类型

Defines in what format to expect the data that fills the grid. Valid options are xml (we expect data in xml format), xmlstring (we expect xml data as string), json (we expect data in JSON format), jsonstring (we expect JSON data as a string), local (we expect data defined at client side (array data))

+0

谢谢。我做了改变它为我工作。 – Chakradhar