Javascript 使用从传递为'的数据派生的数据创建jqgrid fill列;数据';

Javascript 使用从传递为'的数据派生的数据创建jqgrid fill列;数据';,javascript,jquery,jqgrid,Javascript,Jquery,Jqgrid,我正在使用DatatypeLocal制作一个jqgrid,DatatypeLocal是从服务器返回的json数组 jQuery("#my_table").jqGrid( { datatype: "local", colNames: ['ID', 'Name','Status', 'Date'], colModel:[ {name:'id',in

我正在使用DatatypeLocal制作一个jqgrid,DatatypeLocal是从服务器返回的json数组

jQuery("#my_table").jqGrid(
                        { datatype: "local", 
                          colNames: ['ID', 'Name','Status', 'Date'],
                          colModel:[ {name:'id',index:'id', width:50, sorttype:"int"}, 
                                     {name:'name',index:'name', sorttype:"string"}, 
                                     {name:'status',index:'status', width:50, sorttype:"string"}, 
                                     {name:'date',index:'date', width:120, align:"left",sorttype:"date"} ], 
                          data: result,
                          ...});
但是,其中一列status表示为数字

我想将这些数据显示为相应的字符串。例如,状态为1时为“活动”,状态为0时为“非活动”

是否可以直接在jqgrid中执行此操作,例如作为附加的colModel参数或jqgrid方法? 我已经阅读了jqgrid的文档,但没有注意到解决这个问题的方法

我不想更改从服务器返回的数据,因为我认为传递冗余信息没有任何意义

我还希望不必直接在javascript中操作
结果
数组,因为我看不出遍历数组2次有什么意义(一次改变状态,第二次改变jqgrid加载状态)。

js代码中的某个地方:

var status_lines = ['Inactive', 'Active'];
function status_formatter(cellvalue, options, rowObject) {
    return status_lines[cellvalue];
}
然后在colModel中:

{name:'status',index:'status', width:50, sorttype:"string", formatter:status_formatter}
当然,如果您愿意的话,您可以在
formatter:function(c,o,r){…}
样式中执行此操作。

js代码中的某个地方:

var status_lines = ['Inactive', 'Active'];
function status_formatter(cellvalue, options, rowObject) {
    return status_lines[cellvalue];
}
然后在colModel中:

{name:'status',index:'status', width:50, sorttype:"string", formatter:status_formatter}
当然,如果您愿意,您可以使用
formatter:function(c,o,r){…}
样式执行此操作。

您可以使用:

{名称:'status',索引:'status',宽度:50,
格式化程序:'select',editoptions:{value:'0:非活动;1:活动'}}
您可以使用:

{名称:'status',索引:'status',宽度:50,
格式化程序:'select',editoptions:{value:'0:非活动;1:活动'}}

感谢您的提示,这是一个比我需要的更通用的解决方案,但我将在其他情况下使用它!不客气)是的,另一个解决方案更适合您的情况,我只是不知道。谢谢提示,这是一个比我需要的更通用的解决方案,但我将在其他情况下使用它!不客气)是的,另一个解决方案更适合你的情况,我只是不知道。