4

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

1 に答える 1

13

列モデルでカスタム フォーマッターを使用すると、これを簡単に行うことができます。

カスタム フォーマッタは、次のパラメータを持つ JavaScript 関数です。

cellvalue - フォーマットされる値

options - {rowId:rid, colModel:cm} ここで、rowId - 行の ID colModel は、jqGrid の colModel 配列から取得したこの列のプロパティのオブジェクトです

rowObject - datatype オプションから決定される形式で表される行データです

したがって、関数は次のように宣言できます。

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の例を次に示します。

于 2012-08-23T14:47:33.737 に答える