私はまだjqGridにセルを含めることができるかどうかを調べようとしています。その行の編集フォームを表示するときに、その列を複数選択リストとして表示できるGUIが必要です。
これは次のいずれかになります。
- チェックボックスのリスト
- 複数を選択できるように、チェックボックス付きのリストを選択します。
これはjqGridで可能ですか?
jqGridは複数選択編集をサポートしています。選択にceckboxを使用しませんが、select要素を複数選択します。ダブルクリックでインライン編集を使用し
てデモを作成しました。
対応するコードは次のとおりです。
jQuery(document).ready(function() {
var lastSel, mydata = [
{id:0, Name:"Lukas Podolski", Category:"1", Subcategory:"1"},
{id:1, Name:"Michael Schumacher", Category:"1", Subcategory:"2"},
{id:2, Name:"Albert Einstein", Category:"2", Subcategory:"3,4"},
{id:3, Name:"Blaise Pascal", Category:"2", Subcategory:"4"}
], grid = jQuery("#list");
grid.jqGrid({
data: mydata,
datatype: 'local',
colModel: [
{ name: 'Name', index: 'Name', width: 130, editable: true },
{
name: 'Category', index: 'Category', width: 100,
formatter:'select', editable: true, edittype:'select',
editoptions: {
value: '1:sport;2:science',
multiple: true,
size: 2
}
},
{
name: 'Subcategory', index: 'Subcategory', width: 250,
formatter:'select', editable:true, edittype:'select',
editoptions: {
value: '1:football;2:formula 1;3:physics;4:mathematics',
multiple: true,
size: 4
}
}
],
sortname: 'Name',
viewrecords: true,
rownumbers: true,
sortorder: 'desc',
pager: '#pager',
height: '100%',
editurl: 'clientArray',
ondblClickRow: function(rowid) {
jQuery(this).jqGrid('editRow', rowid, true, null, null, 'clientArray');
},
onSelectRow: function(id){
if (id && id!==lastSel){
jQuery(this).restoreRow(lastSel);
lastSel=id;
}
},
caption: 'Selects with multiselect'
});
});
ちなみに、デモの作成中に、完全にサポートされていないIDとして「0」を持つselect要素を使用できないことがわかりました。たとえば、「1:sport; 2:science」は機能しますが、「0:sport; 1:science」は機能しません。'sport'アイテムの選択は保存されません。
チェックボックス付きのより快適なコントロールを使用する必要がある場合は、カスタム編集に関する動作を実装する必要があります。