日期:2014-05-16  浏览次数:20305 次

jqGrid getRowData 問題
我用jqGrid加载数据,数据的json格式如下
JScript code

{'id':1000, 'name':'XXX', 'score':99}


显示的时候要对id字段进行格式化
JScript code

colNames : ['', '名字',  '分数'],
colModel : [
    {name : 'id', width: 80, formatter: idFormatter},
    {name : 'name', width: 80},
    {score : 'score', width : 80}
]
...

function idFormatter(cellvalue, optionals, rowData){
    return '<input type="button" click="delete(' + rowData.id + ')" value="Delete" />';
}


显示正常,没什么问题

但我用jqGrid的getRowData方法取出来的数据是这样的
JScript code

{ 'id': '<input type="button" click="delete(1000)" value="Delete" />','name':'XXX', 'score':'99' }


可以看出有两个问题
1. id字段变成了我格式化以后的值
2. score字段变成了字符串

请问我要怎样才能取回原来的数据?

------解决方案--------------------
用这个getLocalRow,而不是getRowData

getLocalRow 参数:rowid Return the row data from the local array stored in data parameter when the datatype is local

API已经说了getRowData不推荐
1.Do not use this method when you editing the row or cell. This will return the cell content and not the actuall value of the input element.
2.the performance of this method becomes an issue.Do not use this method in the body of “for” and “when”. (When calling this method, it will calculates the row datas one time.)