使用jqGrid单元格数据的键/值对 [英] Using key/value pairs for jqGrid cell data

查看:78
本文介绍了使用jqGrid单元格数据的键/值对的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个jqGrid定义如下:

I have a jqGrid defined as such:

$("#tableFeedbackReports").jqGrid({
            url: '/FeedbackReports/GetFeedbackReport',
            datatype: 'json',
            colNames: ['ColA', 'ColB', 'ColC', 'ColD'],
            colModel: [{ name: 'ColA', index: 'ColA', width: 60 },
                        { name: 'ColB', index: 'ColB', width: 60 },
                        { name: 'ColC', index: 'ColC', width: 60 },
                        { name: 'ColD', index: 'ColD', width: 60 }, 
/* ... and so on */

现在,当ajax调用返回时,它必须返回每行中的数组。 / p>

Now, when the ajax call returns, it's has to return an array of what will go into each row.

['value', 'value', 'value']

是否可以让jqGrid接受行数据的键/值对?

Is it possible to get jqGrid to accept key/value pairs for row data?

[{ 'ColA' : 'value', 'ColB' : 'value', 'ColC' : 'value', 'ColD' : 'value'}]

所以当jqGrid加载数据时,它会自动将数据绑定到模型中的列吗?

So when jqGrid loads the data, it'll automatically binds the data to the column in the model?

推荐答案

看看<$ href =http://www.trirand.com/jqgridwiki/doku.php?id=wiki:retrieving_data =nofollow noreferrer上的 jsonReader 选项> jqGrid Wiki ,特别是其 repeatitems 属性。从该页面:

Have a look at the jsonReader option on the jqGrid Wiki, specifically its repeatitems property. From that page:


repeatitems元素告诉jqGrid
行中数据的信息是可重复的 - 即元素具有在单元格
元素中描述的相同标记单元格。将此选项设置为false会指示jqGrid按名称搜索
中的元素json数据。这是来自colModel的名称或用
描述的名称,colModel中的jsonmap选项。

The repeatitems element tells jqGrid that the information for the data in the row is repeatable - i.e. the elements have the same tag cell described in cell element. Setting this option to false instructs jqGrid to search elements in the json data by name. This is the name from colModel or the name described with the jsonmap option in colModel.

他们的例子是:

jQuery("#gridid").jqGrid({
...
   jsonReader : {
      root:"invdata",
      page: "currpage",
      total: "totalpages",
      records: "totalrecords",
      repeatitems: false,
      id: "0"
   },
...
});

将按以下格式处理数据,包含键/值对:

Which will process data in the following format, with key/value pairs:

{ 
  totalpages: "xxx", 
  currpage: "yyy",
  totalrecords: "zzz",
  invdata : [
    {invid:"1",invdate:"cell11", amount:"cell12", tax:"cell13", total:"1234", note:"somenote"},
    {invid:"2",invdate:"cell21", amount:"cell22", tax:"cell23", total:"2345", note:"some note"},
  ...

]
}

这篇关于使用jqGrid单元格数据的键/值对的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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