概要と基本的な使い方

このサンプルでは、コンボコントロールのドロップダウンリストに階層データを設定する場合、データをツリーとして表示を設定しています。

コンボコントロールでは、データ項目が階層データの場合、ドロップダウンリストに表示する内容をツリーとして表示できます。 データ構造 コンボコントロールのドロップダウンリストをツリーとして表示するには、各データ項目が親子関係を持つように設定します。 以下のように、「children」プロパティを持つ「products」オブジェクトのデータをツリーとしてドロップダウンリストに表示します。「children」プロパティには「products」オブジェクトの配列が含まれ、さらに多くの「children」プロパティで子階層のデータを設定することができます。 ツリービューの設定 dropDownTypeプロパティを利用することで、コンボコントロールのドロップダウンリストの表示形式を設定できます。設定できる値(ComboDropDownType列挙体)は、以下の通りです。既定値はListです。 ComboDropDownTypeの値 説明 List ドロップダウンリストをリストとして表示する Tree ドロップダウンリストをツリーとして表示する ツリービューを有効にするには、dropDownTypeプロパティをComboDropDownType.Treeに設定します。 また、dropDownTreeConfigプロパティに、childrenMemberPathプロパティで子階層のコレクションを指定できます。既定値はchildrenです。 設定例は以下の通りです。 子階層の展開/折りたたみ表示 expandedMemberPathプロパティでドロップダウンリストを開く時に子階層を展開するかどうかを設定できます。既定値はexpandedです。expandedをtrueまたはfalseに設定することで、子階層の展開/折りたたみの表示を切り替えます。 ソート & フィルター & オートコンプリート ツリービューを設定したコンボコントロールはソート、フィルターとオートコンプリート機能をサポートします。フィルターを設定する場合、子ノードが入力内容にヒットすると、折りたたまれたノードが自動的に展開されます。
import '@mescius/inputman/CSS/gc.inputman-js.css'; import './styles.css'; import { InputMan } from '@mescius/inputman'; import { products, gcProducts } from './data'; InputMan.appearanceStyle = InputMan.AppearanceStyle.Modern; new InputMan.GcComboBox(document.getElementById('gcComboBox1'), { items: products, width: 240, dropDownType: InputMan.ComboDropDownType.Tree, displayMemberPath: 'product', }); new InputMan.GcComboBox(document.getElementById('gcComboBox2'), { items: gcProducts, dropDownType: InputMan.ComboDropDownType.Tree, itemHeight: 50, dropDownWidth: 540, width: 240, displayMemberPath: 'name', valueMemberPath: 'name', dropDownTreeConfig: { selectableNodeType: InputMan.TreeViewNodeType.Leaf, itemTemplate: [ `<div class="template-parent-item"> <span>{!product}</span> </div>`, `<div class="template-item"> <div class="image"><img src="{!logo}"></div> <div class="names"><div class="name">{!name}</div><div class="category">{!category}</div></div> <div class="description">{!description}</div> </div>`, ], selectTemplate: (args) => { if (args.item.type === 'parent') { return args.template[0]; } return args.template[1]; }, }, });
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>コンボコントロール - ツリービュー - 概要と基本的な使い方</title> <!-- SystemJS --> <script src="node_modules/systemjs/dist/system.src.js"></script> <script src="systemjs.config.js"></script> <script> window.onload = function() { System.import('./src/app'); } </script> </head> <body> <div class="flexbox"> <div> 単純なリスト<br> <select id="gcComboBox1"></select> </div> <div> テンプレート<br> <select id="gcComboBox2"></select> </div> </div> </body> </html>
.template-parent-item { display: flex; align-items: center; font-weight: bold; height: 100%; } .template-item { height: 50px; display: flex; justify-content: center; align-items: center; } .template-item>* { margin: 0 5px; } .image { width: 40px; height: 40px; } .image img { width: 40px; } .names { width: 150px; } .name { font-size: 16px; font-weight: bold; color: #2676c0; } .description { width: 210px; white-space: normal; }
export const products = [{ product: 'ジュース', children: [{ product: 'ストレートジュース', children: ['果汁100%オレンジ', '果汁100%グレープ', '果汁100%レモン', '果汁100%ピーチ'], expanded: true, }, { product: 'ブレンドジュース', children: ['オレンジブレンド', 'グレープブレンド', 'レモンブレンド', 'ピーチブレンド'] } ], expanded: true, }, { product: 'コーヒー', children: ['コーヒーマイルド', 'コーヒービター'], }]; export const gcProducts = [ { product: '帳票・ドキュメント関連製品', children: [ { logo: '$IMDEMOROOT$/ja/samples/comboBox/treeview/basic/img/AR.png', name: 'ActiveReports', category: '帳票・レポート', description: '日本仕様の帳票開発に必要な機能を搭載したコンポーネント', }, { logo: '$IMDEMOROOT$/ja/samples/comboBox/treeview/basic/img/SP.png', name: 'SPREAD', category: '表計算・グリッド', description: 'Excel風のビューと表計算機能を実現するUIコンポーネント', }, { logo: '$IMDEMOROOT$/ja/samples/comboBox/treeview/basic/img/DD.png', name: 'DioDocs', category: 'ドキュメントAPI', description: 'ドキュメントを生成、更新するAPIライブラリ', }, ], expanded: true, type: 'parent', }, { product: '入力・UI関連製品', children: [ { logo: '$IMDEMOROOT$/ja/samples/comboBox/treeview/basic/img/C1.png', name: 'ComponentOne', category: 'コンポーネントセット', description: 'Visual Studioで利用する.NET Framework用コンポーネント', }, { logo: '$IMDEMOROOT$/ja/samples/comboBox/treeview/basic/img/IM.png', name: 'InputMan', category: '入力支援', description: '快適な入力を実現する日本仕様入力コンポーネントセット', }, { logo: '$IMDEMOROOT$/ja/samples/comboBox/treeview/basic/img/MR.png', name: 'MultiRow', category: '多段明細', description: '1レコード複数行&日付表示に最適なグリッドコンポーネント', }, ], expanded: true, type: 'parent', }, ];
body { min-height: 350px; } [gcim-control-appearance="modern"] .viewport { line-height: 1.3; } [gcim-control-appearance="modern"] .template-parent-item { display: flex; align-items: center; font-weight: bold; height: 100%; } [gcim-control-appearance="modern"] .template-item { height: 50px; display: flex; justify-content: center; align-items: center; } [gcim-control-appearance="modern"] .template-item>* { margin: 0 5px; } [gcim-control-appearance="modern"] .image { width: 40px; height: 40px; } [gcim-control-appearance="modern"] .image img { width: 40px; } [gcim-control-appearance="modern"] .names { width: 150px; } [gcim-control-appearance="modern"] .name { font-size: 16px; font-weight: bold; color: #2676c0; } [gcim-control-appearance="modern"] .category { font-size: 12px; color: green; } [gcim-control-appearance="modern"] .description { width: 210px; white-space: normal; } [gcim-control-appearance="modern"] .list-item[selected="true"] .name, [gcim-control-appearance="modern"] .list-item[selected="true"] .category { color: white; } [gcim-control-appearance="modern"] .odd { background: aliceblue; }
System.config({ transpiler: 'plugin-babel', babelOptions: { es2015: true }, meta: { '*.css': { loader: 'css' } }, paths: { // paths serve as alias 'npm:': 'node_modules/' }, // map tells the System loader where to look for things map: { '@mescius/inputman': 'npm:@mescius/inputman/index.js', '@mescius/inputman/CSS': 'npm:@mescius/inputman/CSS', 'css': 'npm:systemjs-plugin-css/css.js', 'plugin-babel': 'npm:systemjs-plugin-babel/plugin-babel.js', 'systemjs-babel-build': 'npm:systemjs-plugin-babel/systemjs-babel-browser.js' }, // packages tells the System loader how to load when no filename and/or no extension packages: { src: { defaultExtension: 'js' }, "node_modules": { defaultExtension: 'js' }, } });