我想知道如何在 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 */
}
},
...
]
});
最佳答案
您可以通过在列模型上使用 Custom Formatter 轻松完成此操作。
自定义格式化程序是具有以下参数的 javascript 函数:
cellvalue - The value to be formatted
options - { rowId: rid, colModel: cm} where rowId - is the id of the row colModel is the object of the properties for this column getted from colModel array of jqGrid
rowObject - is a row data represented in the format determined from datatype option
所以一个函数可以这样声明:
function myformatter ( cellvalue, options, rowObject )
{
// format the cellvalue to new format
return new_formated_cellvalue;
}
并在您的列上定义如下:
{name:'price', index:'price', width:60, align:"center", editable: true,
formatter:myformatter },
因此,在您的情况下,您可以使用自定义格式化程序中的 rowObject 参数来填充您的附加值。
例如。
列模型
{name:'employee_id', index:'employee_id', width:60, align:"center", editable: true,
formatter:myformatter, label:'Employee' }
格式化程序
function myformatter ( cellvalue, options, rowObject )
{
return cellvalue + ' ' + rowObject.email + ' ' + rowObject.user_name;
}
如果这是在您的 employee_id 列上定义的,它将显示在单元格中:
employee_id email username
这是一个 jsFiddle 示例,显示了它的工作原理。
关于jqgrid - 如何在jqgrid的同一列中显示多个值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12079172/