我用jqGrid加载数据,数据的json格式如下{'id':1000, 'name':'XXX', 'score':99}显示的时候要对id字段进行格式化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方法取出来的数据是这样的{ 'id': '<input type="button" click="delete(1000)" value="Delete" />','name':'XXX', 'score':'99' }可以看出有两个问题
1. id字段变成了我格式化以后的值
2. score字段变成了字符串请问我要怎样才能取回原来的数据?

解决方案 »

  1.   

    用这个getLocalRow,而不是getRowDatagetLocalRow 参数:rowid Return the row data from the local array stored in data parameter when the datatype is localAPI已经说了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.) 
      

  2.   

    错了。。是datatype is local时才行那就不晓得了..
      

  3.   

    我找到了一种麻烦一点的方法
    首先用getGridParam('data')获取jqGrid的数据列表
    然后根据rowid到列表去取, getGridParam('data')[rowid - 1]关键是jsonReader{ id: idName }中的idName,在colModel中不能有一个字段名称跟跟idName一样
    如果字段列表没有idName字段,则rowid为1, 2, 3...
    如果字段列表中有idName字段,则rowid为该字段的值这时候就等循环getGridParam('data')去找出对应的数据了
      

  4.   

    把id的那一列做成隐藏的,delete单独一列 delete 的formater  中可以通过rowData取到id ,另外你说的数据类型可以自己转换啊。
      

  5.   

    你要先获取 全部的,也就是你选中的,
    var gars = jQuery("#list").jqGrid('getGridParam', 'selarrrow');
    var rowIds = [];
    for ( var rowId in gsrs) {
     var row = jQuery('#list').jqGrid(
    'getRowData', gsrs[rowId]);
     rowIds.push(row.id);
    }
      try {
     for ( var i = 0; i < rowIds.length; ++i) {
         deleteEntry('URL', rowIds[i]);
    }
    } catch (err) {
            var msg = "服务器内部错误,请重试。";
     alert(msg);
    }
      

  6.   

    兄弟,可能你有沒有看清楚我的問題
    getRowData得到的是格式化之後的數據。而且所有的屬性都會變成字符串問題已經解決了,方法在3樓