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

时间:2012-08-22 18:25:03

标签: 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 */ 
  } 
 }, 
...
]
});

1 个答案:

答案 0 :(得分:13)

您可以使用列模型上的Custom Formatter轻松完成此操作。

自定义Formatter是一个带有以下参数的javascript函数:

  

cellvalue - 要格式化的值

     

options - {rowId:rid,colModel:cm}其中rowId - 是的id   row colModel是此列getted的属性的对象   来自jqGrid的colModel数组

     

rowObject - 是以确定的格式表示的行数据   数据类型选项

因此可以像这样声明一个函数:

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示例,显示它正常工作。

相关问题