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

编程入门 行业动态 更新时间:2024-10-27 06:28:02
本文介绍了如何在jqgrid的同一列中显示多个值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想知道如何在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的同一列中显示多个值

本文发布于:2023-10-26 11:06:22,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1529952.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多个   如何在   jqgrid

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!