【发布时间】:2010-01-20 13:26:53
【问题描述】:
我正在尝试 jqGrid 从 django 获取一些 json 数据的来源:link
不幸的是,jqgrid中没有显示数据,只有一个空的jqgrid。
我正在用这个调用渲染 jqgrid:
<script type="text/javascript">
$(function () {
$.getJSON("{% url myapp.views_json.grid_config %}", function(data){
$("#mygrid")
.jqGrid(data)
.navGrid('#pager',
{add: false, edit: false, del: false, view: true},
{}, // edit options
{}, // add options
{}, // del options
{ multipleSearch:true, closeOnEscape:true }, // search options
{ jqModal:false, closeOnEscape:true} // view options
);
});
});
</script>
{% url myapp.views_json.grid_config %} 被解析为 url “projects/examplegrid/cfg/”。当我在浏览器中调用此 URL 时,它会返回 JSON 数据。请点击链接查看。 json config data
这应该没问题。我猜.. 在这个 json 数据文件中,您会看到一个 url:http://127.0.0.1:8000/pm/projects/examplegrid/ 这个 url 也返回 json 数据。这是我要呈现的数据的 json 表示。在此处查看此 json 数据集:link
这是生成的 jqgrid 的屏幕截图。 link 我知道在这里帮助我可能很难。但在我看来,我的问题出在 jqgrid 方面,我认为外面有很多裂缝,谁知道该由谁来处理它。我没有:-)
编辑:未定义的错误消失了。此错误是由于缺少对本地文件的引用:
<script type="text/javascript" src="http://localhost:8000/media/js/i18n/grid.locale-en.js"></script>
但下一个错误是,它显示“正在加载”并且没有完成。有谁知道问题出在哪里?
编辑:错误显然是 jqgrid 没有正确初始化。我使用了 CalebD 提出的 wiki 页面,它现在可以工作了。至少 json 数据呈现在网格中。我现在想知道我必须做什么才能更新一行。
<script type="text/javascript">
jQuery(document).ready(function(){
jQuery("#grid").jqGrid({
url:'http://127.0.0.1:8000/pm/projects/examplegrid/',
datatype: "json",
mtype: 'GET',
colNames:['id', 'description'],
colModel:[
{name:'id',index:'id', width:55, sortable:false, editable:false, editoptions:{readonly:true,size:10}},
{name:'description',index:'description', width:300, editable:true},
],
jsonReader : {
repeatitems:false
},
rowNum:10,
rowList:[10,20,30],
pager: jQuery('#gridpager'),
sortname: 'name',
viewrecords: true,
sortorder: "asc",
caption:"Wines",
editurl:"http://127.0.0.1:8000/pm/projects/examplegrid/"
}).navGrid('#gridpager');
});
</script>
【问题讨论】: