jqgrid - 如何在jqgrid的同一列中显示多个值

标签 jqgrid

我想知道如何在 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/

相关文章:

javascript - 如何将包含 <br> 的选项字符串分配给 jqGrid 的版本值属性

javascript - 如何将 jQgrid 格式化函数中的对象参数分配给函数?

jquery - jqgrid中的"Undefined"消息,"b.jgrid.formatter is undefined"

javascript - 显示jqGrid滚动条的当前位置

jqGrid 如何使用 EditUrl

jqgrid - 如何在 jqGrid 中编辑或添加新行

jquery - 如何在复选框单击时选择 jqGrid 行?

jquery-ui - 如何在jqgrid中将单列标题文本包装为多行

javascript - Jquery:表内行的内联编辑

javascript - jqgrid - 在 loadComplete 事件上访问 XmlHttpRequest