How to display multiple values ​​in one column in jqgrid

I would like to know how to display multiple values ​​in one column in jqGrid

Here is an example 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 */ } }, ... ] }); 
+4
source share
1 answer

You can do this easily using custom formatting in your column model.

Custom Formatter is a javascript function with the following parameters:

cellvalue - value to be formatted

options - {rowId: rid, colModel: cm}, where rowId is the identifier row colModel is the property object for this getted column from the colModel jqGrid array

rowObject is row data represented in a format defined from a data type

Thus, a function can be declared like this:

 function myformatter ( cellvalue, options, rowObject ) { // format the cellvalue to new format return new_formated_cellvalue; } 

And is defined in your column as follows:

  {name:'price', index:'price', width:60, align:"center", editable: true, formatter:myformatter }, 

So, in your case, you can use the rowObject parameter in custom formatting to populate your extra values. For instance.

Column model

  {name:'employee_id', index:'employee_id', width:60, align:"center", editable: true, formatter:myformatter, label:'Employee' } 

Formatter

 function myformatter ( cellvalue, options, rowObject ) { return cellvalue + ' ' + rowObject.email + ' ' + rowObject.user_name; } 

And if it is defined in the employee_id column, it will be displayed in the cell:

 employee_id email username 

Here is a jsFiddle example showing that it works.

+13
source

All Articles