我想知道如何在jqGrid的单个列中显示多个值
I would like to know how to display multiple values in a single column in jqGrid
这是我当前网格定义的示例.
Here is a sample of my current grid definition.
$("#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 */ } }, ... ] });推荐答案
您可以使用自定义格式化程序.
自定义格式化程序是具有以下参数的javascript函数:
A custom Formatter is a javascript function with the following parameters:
单元格值-要格式化的值
cellvalue - The value to be formatted
选项-{rowId:rid,colModel:cm}其中rowId-是 colModel行是获取此列的属性的对象 来自jqGrid的colModel数组
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-是以以下格式确定的格式表示的行数据: 数据类型选项
rowObject - is a row data represented in the format determined from datatype option
因此可以这样声明一个函数:
So a function can be declared like so:
function myformatter ( cellvalue, options, rowObject ) { // format the cellvalue to new format return new_formated_cellvalue; }并且在您的列上这样定义:
And is defined on your column like this:
{name:'price', index:'price', width:60, align:"center", editable: true, formatter:myformatter },因此,在您的情况下,可以在自定义格式程序中使用rowObject参数来填充其他值. 例如.
So in your case you can use the rowObject parameter in the custom formatter to populate your additional values. For Example.
列模型
{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列上定义了此参数,它将显示在单元格中:
And if this is defined on your employee_id column it would display in the cell:
employee_id email username下面是一个 jsFiddle 示例,显示了它的工作原理.
Here is a jsFiddle example showing it working.
更多推荐
如何在jqgrid的同一列中显示多个值
发布评论