我想知道如何在jqGrid中的单个列中显示多个值
以下是我当前网格定义的示例.
$("#grid1").jqGrid({
url: 'Default.aspx/getGridData',
datatype: 'json',
...
colModel: [
...
//contains the input type ('select', etc.)
{ name: 'InputType', hidden:true },
...
//may contain a string of select options ('<option>Option1</option>'...)
{
name: 'Input',
editable:true,
edittype:'custom',
editoptions:{
custom_element: /* want cell value from InputType column here */ ,
custom_value: /* want cell value from Input column here */
}
},
...
]
});
Run Code Online (Sandbox Code Playgroud)
Dis*_*ame 13
您可以使用列模型上的自定义格式化程序轻松完成此操作.
自定义Formatter是一个带有以下参数的javascript函数:
cellvalue - 要格式化的值
options - {rowId:rid,colModel:cm}其中rowId - 是行的id colModel是从jqGrid的colModel数组获取的此列的属性的对象
rowObject - 是以datatype选项确定的格式表示的行数据
所以函数可以这样声明:
function myformatter ( cellvalue, options, rowObject )
{
// format the cellvalue to new format
return new_formated_cellvalue;
}
Run Code Online (Sandbox Code Playgroud)
并在您的列上定义如下:
{name:'price', index:'price', width:60, align:"center", editable: true,
formatter:myformatter },
Run Code Online (Sandbox Code Playgroud)
因此,在您的情况下,您可以使用自定义格式化程序中的rowObject参数来填充其他值.例如.
列模型
{name:'employee_id', index:'employee_id', width:60, align:"center", editable: true,
formatter:myformatter, label:'Employee' }
Run Code Online (Sandbox Code Playgroud)
格式化
function myformatter ( cellvalue, options, rowObject )
{
return cellvalue + ' ' + rowObject.email + ' ' + rowObject.user_name;
}
Run Code Online (Sandbox Code Playgroud)
如果在employee_id列上定义了它,它将显示在单元格中:
employee_id email username
Run Code Online (Sandbox Code Playgroud)
这是一个显示它工作的jsFiddle示例.