cargoj 2011-06-14 10:28 采纳率: 100%
浏览 531
已采纳

jqgrid grid中的rowid与数据有关系吗?我在用updateGridRows时弄糊涂了

updateGridRows(data,rowidname,jsonreader)

返回解释
true on success,
false otherwise This method update the existing data in the grid by given rowidname.

参数解释
data is a array of data in format
[{name:value,name1:value1…}, {name:value,name2:value2…}]
where the name is the name from colModel and value is the actuall value. It is not neccessary that all columns are present in the data item object (the same as setRowData method)
rowidname (string) - is the name of the row which should acts as id If not set the name “id” is used.
jsonreader (boolean) default false. If set to true a jsonReader definition is used to set the data. Note that this work only if the item in jsonReader object 'repeatitems' is set to true.In this case the data should be not in pair name:value, but only values where the number of columns should be equal of those in colModel.

rowidname:作为行ID的名称。困惑???这指的是从数据的列中选一列?这里面就有一个问题了,既然rowid与数据行主键列不是一个东西,为什么方法的参数不是rowid,而是rowidname?实际我也测试过,这里写rowid能执行不报错,但是无法更新grid。

如果GRID排序方式是按照数据主键列desc排序,updateGridRows就会有问题。比如,第一行的主键列500,而rowid是1;最后一行主键列是1,而rowid是500,这样如果使用updateGridRows更新最后一行,实际结果却是刷新了第一行。
同样未经测试的推想,如果数据主键不连续、主键不是整型而是GUID,这样同样会得到错误的执行结果。

糊涂1:grid的rowid与数据行主键是一个东西吗?
糊涂2:updateGridRows中 rowidname 指的是什么?

  • 写回答

1条回答 默认 最新

  • conanca 2011-06-14 10:51
    关注

    1.可以不用"id"用自己定义的。
    2.rowidname就是你自己定义的主键的列名

    这个例子给你点启示:

    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.

    Here is an example:

    jQuery("#gridid").jqGrid({
    ...
    jsonReader : {
    root:"invdata",
    page: "currpage",
    total: "totalpages",
    records: "totalrecords",
    repeatitems: false,
    id: "0"
    },
    ...
    });The resulting data in our example should be:

    {
    "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"},
    ...
    ]
    }The id element in this case is 'invid'.

    A very useful feature here (repeatitems:false) is that there is no need to include all the data that is represented in colModel. Since we make a search by name, the order does not need to match the order in colModel. Hence the following string will be correctly interpreted in jqGrid.

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?