使用 jqGrid 的自定义 JSON 格式

发布于 2024-11-04 20:48:48 字数 626 浏览 5 评论 0原文

我有一个 JSON 文件,其格式必须如下。如何让 jqGrid 使用 jsonmap、colModel 或 jsonReader 选项解释此格式?

[
  {
    "element1" : {
      "subElement1" : "value",
      "subElement2" : "value"
    }
    "element2" : {
      "subElement3" : "value",
      "subElement4" : "value"
    }
  }, 

  {
    "element1" : {
      "subElement1" : "value",
      "subElement2" : "value"
    }
    "element2" : {
      "subElement3" : "value",
      "subElement4" : "value"
    },

    // . . . etc. . . .
  }
]

colNames 将是 ["subElement1", "subElement2", "subElement3", "subElement4"]

非常感谢您的帮助。

I have a JSON file that must be formatted as follows. How can I have jqGrid interpret this format using the jsonmap, colModel, or jsonReader options?

[
  {
    "element1" : {
      "subElement1" : "value",
      "subElement2" : "value"
    }
    "element2" : {
      "subElement3" : "value",
      "subElement4" : "value"
    }
  }, 

  {
    "element1" : {
      "subElement1" : "value",
      "subElement2" : "value"
    }
    "element2" : {
      "subElement3" : "value",
      "subElement4" : "value"
    },

    // . . . etc. . . .
  }
]

colNames will be ["subElement1", "subElement2", "subElement3", "subElement4"].

Thanks a lot for any help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

沧笙踏歌 2024-11-11 20:48:48

您始终可以在此处阅读有关格式化的 jQGrid API:
http://www.trirand.com/jqgridwiki/doku.php?id =wiki:colmodel_options

考虑到您的值都是字符串,为您提供自定义格式化程序有点棘手...它也支持货币和日期排序。

演示在此处提供源代码: http://www.trirand.com/blog/jqgrid/ jqgrid.html

另外,非常确定您可以指定一个函数作为格式,并在该函数中返回格式化值。例如,我编写了一个函数,它接受一个状态并返回一个带有该状态图标的图像。

这是一个例子:

jQuery("#list2").jqGrid({
    url:'server.php?q=2',
    datatype: "json",
    colNames:['Inv No','Date', 'Client', 'Amount','Tax','Total','Notes'],
    colModel:[
        {name:'id',index:'id', width:55},
        {name:'invdate',index:'invdate', width:90},
        {name:'name',index:'name asc, invdate', width:100},
        {name:'amount',index:'amount', width:80, align:"right"},
        {name:'tax',index:'tax', width:80, align:"right"},      
        {name:'total',index:'total', width:80,align:"right"},       
        {name:'note',index:'note', width:150, sortable:false}       
    ],
    rowNum:10,
    rowList:[10,20,30],
    pager: '#pager2',
    sortname: 'id',
    viewrecords: true,
    sortorder: "desc",
    caption:"JSON Example"
});

You could always just read the jQGrid API on formatting here:
http://www.trirand.com/jqgridwiki/doku.php?id=wiki:colmodel_options

Kind of tricky to provide you with custom formatters considering your values are all strings... It supports sorting for curreny and dates as well.

The demos provide source code here: http://www.trirand.com/blog/jqgrid/jqgrid.html

Also, pretty sure you can just specify a function as the format and in that function return the formatted value. For example, I wrote a function that took a status and returned an image with an icon for that status.

Here's an example:

jQuery("#list2").jqGrid({
    url:'server.php?q=2',
    datatype: "json",
    colNames:['Inv No','Date', 'Client', 'Amount','Tax','Total','Notes'],
    colModel:[
        {name:'id',index:'id', width:55},
        {name:'invdate',index:'invdate', width:90},
        {name:'name',index:'name asc, invdate', width:100},
        {name:'amount',index:'amount', width:80, align:"right"},
        {name:'tax',index:'tax', width:80, align:"right"},      
        {name:'total',index:'total', width:80,align:"right"},       
        {name:'note',index:'note', width:150, sortable:false}       
    ],
    rowNum:10,
    rowList:[10,20,30],
    pager: '#pager2',
    sortname: 'id',
    viewrecords: true,
    sortorder: "desc",
    caption:"JSON Example"
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文