jqGrid-JSON请求中的数据未填充表 [英] jqGrid - Table not being populated by data from json request

查看:46
本文介绍了jqGrid-JSON请求中的数据未填充表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用jqGrid显示网格.一切似乎都正常.该表正在被渲染,但是所有单元格都为空.所有其他信息都在表上(页码,总页数,行数).尝试更改页面时,可以毫无问题地检索json数据.

I am trying to get a grid displayed using jqGrid. Everything seems to work fine. The table is being render, but all the cells are empty. All the other infos are on the table (page number, total pages, number of rows). When trying to change page, the json data is being retrieved without any problem.

这是我的代码的一部分:

Here is a snip of my code:

<script type="text/javascript">
$(document).ready(function() {
  $("#list2").jqGrid({
      url:'/ajax/list/facture',
      datatype: "json",          
      colModel:[
       {label:'N° d\'article', name: 'code', width:90},
       {label:'Article', name: 'article', width:100},
       {label:'Entrepôt', name: 'entrepot', width:80, align:"right"},
       {label:'Limite', name: 'limite', width:80, align:"right"},
       {label:'À commander', name: 'qte_a_commander', width:80,align:"right"},
       {label:'Déjà commander', name: 'qte_deja_commander', width:150},
       {label:'Coût', name: 'cout', width:150},
       {label:'Prix', name: 'prix', width:150},
       {label:'Coût total', name: 'cout_total', width:150}
      ],
      rowNum:100,
      scoll: true,
      //rowList:[10,20,30],
      pager: '#pager2',
      //sortname: 'code',
      viewrecords: true,
      sortorder: "desc",
      jsonReader: {
        repeatitems : false,
        id: "0"
      },
      //sortorder: "desc",
      caption:"Inventaire",

      width: 1200,
      height: 200


  });

  $("#list2").jqGrid('navGrid','#pager2',{edit:false,add:false,del:false});


 });


</script>

<table id="list2"></table>
<div id="pager2"></div>

我的json数据正在发送:

My json data being sent:

{
  "page":"1",
  "total":33,
  "records":"100",
  "rows":[
    {"id":1,"cell":{"code":"0064NB","article":"Livre","entrepot":"4","limite":"3","qte_a_commander":"3","qte_deja_commander":"0","cout":"3.40","prix":"30.99","cout_total":"13.60"}},
    {"id":2,"cell":{"code":"0072NB","article":"Livre et corrig\u00e9","entrepot":"5","limite":"3","qte_a_commander":"3","qte_deja_commander":"0","cout":"3.40","prix":"30.99","cout_total":"17.00"}}
    /*[... got over 100 fields ...]*/
  ]}  

推荐答案

好吧,它能够使用索引而不是名称来工作

Well, was able to get it working using index instead of names

  colModel:[
   {label:'Code', index: 'code', width:90},
   {label:'Article', index: 'article', width:100},
   {label:'Entrepôt', index: 'entrepot', width:80, align:"right"},
   {label:'Limite', index: 'limite', width:80, align:"right"},
   {label:'À commander', index: 'qte_a_commander', width:80,align:"right"},
   {label:'Déjà commander', index: 'qte_deja_commander', width:150},
   {label:'Coût', index: 'cout', width:150},
   {label:'Prix', index: 'prix', width:150},
   {label:'Coût total', index: 'cout_total', width:150}
  ],

并且不命名我的json数据:

And by not naming my json data:

{
  "page":"1",
  "total":33,
  "records":"100",
  "rows":
    [
      {"id":1,"cell":["0064NB","Livre","4","3","3","0","3.40","30.99","13.60"]},
      {"id":2,"cell":["0072NB","Livre corrig\u00e9","5","3","3","0","3.40","30.99","17.00"]}
    ]
}

这篇关于jqGrid-JSON请求中的数据未填充表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆