<!DOCTYPE html>
<html>
<head>
<base href="." />
<title>Angular 2 Multiple Selection</title>
<link rel="stylesheet" href="style.css" />
<script src="https://unpkg.com/zone.js/dist/zone.js"></script>
<script src="https://unpkg.com/zone.js/dist/long-stack-trace-zone.js"></script>
<script src="https://unpkg.com/reflect-metadata@0.1.3/Reflect.js"></script>
<script src="https://unpkg.com/systemjs@0.19.31/dist/system.js"></script>
<script src="config.js"></script>
<script>
System.import('app')
.catch(console.error.bind(console));
</script>
</head>
<body>
<my-app>
loading...
</my-app>
</body>
</html>
multiple-select {
position: relative;
display: inline-block;
}
label{
cursor: pointer;
}
multiple-select input[type="checkbox"] {
margin: 0;
}
multiple-select button {
width: 100%;
height: 34px;
color: #333;
background-color: #fff;
border-color: #ccc;
padding: 5px 10px;
cursor: pointer;
background-image: none;
border: 1px solid #cccccc;
border-radius: 4px;
text-align: left;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
font-size: 13px;
font-weight: normal;
line-height: 20px;
}
multiple-select button:hover {
-webkit-box-shadow: inset 0 3px 5px rgba(0, 0, 0, 0.125);
box-shadow: inset 0 3px 5px rgba(0, 0, 0, 0.125);
color: #333;
background-color: #e6e6e6;
border-color: #adadad;
}
multiple-select button:focus {
-webkit-box-shadow: inset 0 3px 5px rgba(0, 0, 0, 0.125);
box-shadow: inset 0 3px 5px rgba(0, 0, 0, 0.125);
color: #333;
background-color: #e6e6e6;
border-color: #8c8c8c;
}
multiple-select button .i-down {
float: right;
}
multiple-select .show-tree-view {
position: absolute;
top: 100%;
left: 0;
z-index: 1000;
float: left;
width: 100%;
margin: 0px;
font-size: 14px;
text-align: left;
list-style: none;
background-color: #fff;
-webkit-background-clip: padding-box;
background-clip: padding-box;
border: 1px solid #ccc;
border: 1px solid rgba(0, 0, 0, 0.15);
border-radius: 4px;
-webkit-box-shadow: 0 6px 12px rgba(0, 0, 0, 0.175);
box-shadow: 0 6px 12px rgba(0, 0, 0, 0.175);
}
multiple-select .show-tree-view .tree-view-content {
display: inline-block;
width: 100%;
overflow: auto;
}
multiple-select .show-tree-view .dropdown-header {
border-bottom: 1px solid darkgray;
padding: 0 10px;
height: 25px;
line-height: 25px;
}
multiple-select .show-tree-view .dropdown-header label {
display: inline-block;
margin-bottom: 0;
cursor: pointer;
}
multiple-select .show-tree-view .dropdown-header .i-up {
float: right;
}
multiple-select .show-tree-view .dropdown-header .i-down {
float: right;
}
multiple-select tree-view ul {
margin: 0 0 0 15px;
-webkit-margin-before: 0;
-webkit-margin-after: 0;
list-style-type: none;
padding: 0;
}
multiple-select tree-view .multiple-select-item {
display: flex;
}
multiple-select tree-view .multiple-select-item:hover {
background: aliceblue;
}
multiple-select tree-view .multiple-select-item .i-expanded {
cursor: pointer;
width: 0;
height: 0;
display: inline-block;
vertical-align: middle;
margin-right: 5px;
margin-top: 4px;
border-top: 4px dashed;
border-right: 4px solid transparent;
border-left: 4px solid transparent;
}
multiple-select tree-view .multiple-select-item .i-collapsed {
cursor: pointer;
width: 0;
height: 0;
display: inline-block;
vertical-align: middle;
margin-right: 9px;
margin-top: 3px;
border-left: 4px dashed;
border-top: 4px solid transparent;
border-bottom: 4px solid transparent;
}
multiple-select tree-view .multiple-select-item .margin-left-13 {
margin-left: 13px;
}
multiple-select .i-down {
cursor: pointer;
width: 0;
height: 0;
display: inline-block;
vertical-align: middle;
margin-top: 10px;
border-top: 4px dashed;
border-right: 4px solid transparent;
border-left: 4px solid transparent;
}
multiple-select .i-up {
cursor: pointer;
width: 0;
height: 0;
display: inline-block;
vertical-align: middle;
margin-top: 8px;
border-bottom: 4px dashed;
border-right: 4px solid transparent;
border-left: 4px solid transparent;
}
### Angular Starter Plunker - Typescript
System.config({
//use typescript for compilation
transpiler: 'typescript',
//typescript compiler options
typescriptOptions: {
emitDecoratorMetadata: true
},
paths: {
'npm:': 'https://unpkg.com/'
},
//map tells the System loader where to look for things
map: {
'app': './src',
'@angular/core': 'npm:@angular/core/bundles/core.umd.js',
'@angular/common': 'npm:@angular/common/bundles/common.umd.js',
'@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.js',
'@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.js',
'@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js',
'@angular/http': 'npm:@angular/http/bundles/http.umd.js',
'@angular/router': 'npm:@angular/router/bundles/router.umd.js',
'@angular/forms': 'npm:@angular/forms/bundles/forms.umd.js',
'@angular/core/testing': 'npm:@angular/core/bundles/core-testing.umd.js',
'@angular/common/testing': 'npm:@angular/common/bundles/common-testing.umd.js',
'@angular/compiler/testing': 'npm:@angular/compiler/bundles/compiler-testing.umd.js',
'@angular/platform-browser/testing': 'npm:@angular/platform-browser/bundles/platform-browser-testing.umd.js',
'@angular/platform-browser-dynamic/testing': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic-testing.umd.js',
'@angular/http/testing': 'npm:@angular/http/bundles/http-testing.umd.js',
'@angular/router/testing': 'npm:@angular/router/bundles/router-testing.umd.js',
'rxjs': 'npm:rxjs',
'typescript': 'npm:typescript/lib/typescript.js',
'angular-2-multiple-selection': 'npm:angular-2-multiple-selection'
},
//packages defines our app package
packages: {
app: {
main: './main.ts',
defaultExtension: 'ts'
},
rxjs: {
defaultExtension: 'js'
},
'angular-2-multiple-selection': {
defaultExtension: 'ts'
}
}
});
//main entry point
import {platformBrowserDynamic} from '@angular/platform-browser-dynamic';
import {AppModule} from './app.module';
platformBrowserDynamic().bootstrapModule(AppModule)
//our root app component
import {Component, NgModule} from '@angular/core'
import { FormsModule } from '@angular/forms';
import {BrowserModule} from '@angular/platform-browser'
import { MultipleSelect } from "angular-2-multiple-selection/multiple-select";
import { AppComponent } from "./app.component";
@NgModule({
imports: [ BrowserModule, FormsModule ],
declarations: [ AppComponent, MultipleSelect ],
bootstrap: [ AppComponent ]
})
export class AppModule {}
import { Component } from "@angular/core";
import { ItemsSelect } from "angular-2-multiple-selection/sources/models/items-select";
import { MultipleSelect } from "angular-2-multiple-selection/sources/models/multiple-select";
@Component({
selector: 'my-app',
template: `
<div>
<multiple-select [multipleSelect]="multipleSelect" (loseFocus)="getValue()"></multiple-select>
</div>
<br>
<input type="button" (click)="getValue()" value="Get Value">: {{value}}
`,
})
export class AppComponent {
multipleSelect: MultipleSelect = new MultipleSelect();
value: string;
constructor() {
this.insertData();
this.value = this.multipleSelect.getValueItems();
}
insertData() {
// id, value, text, checked, expanded, enable
let item1 = new ItemsSelect(1, 1, 'Item 1', true, true, true, []);
let item9 = new ItemsSelect(9, 9, 'Item 9', true, true, true, []);
let item10 = new ItemsSelect(10, 10, 'Item 10', false, true, true, []);
let item11 = new ItemsSelect(11, 11, 'Item 11', true, true, true, [item9, item10]);
let item8 = new ItemsSelect(8, 8, 'Item 8', true, true, true, [item11]);
let item2 = new ItemsSelect(2, 2, 'Item 2', true, true, true, [item1, item8]);
let item4 = new ItemsSelect(4, 4, 'Item 4', true, true, true, []);
let item3 = new ItemsSelect(3, 3, 'Item 3', false, true, true, [item2, item4]);
let item5 = new ItemsSelect(5, 5, 'Item 5', false, true, true, []);
let item6 = new ItemsSelect(6, 6, 'Item 6', true, true, true, []);
let item7 = new ItemsSelect(7, 7, 'Item 7', true, true, true, [item5, item6]);
this.multipleSelect.items = [item3, item7];
this.multipleSelect.showHeader = true // true
this.multipleSelect.numberItemsDisplay = 4; // 3
this.multipleSelect.checkAllCheckBoxText = 'Check All'; // 'Check All Items'
this.multipleSelect.noneItemCheckedText = 'None'; // 'None Selected'
this.multipleSelect.allItemsCheckedText = 'All'; // 'All Items Checked'
this.multipleSelect.subfixNumberItemsCheckedText = ' checked'; // ' selected'
this.multipleSelect.characterValue = '^'; // ','
this.multipleSelect.characterText = ' - '; // ', '
this.multipleSelect.maxHeight = '200px'; // '350px'
this.multipleSelect.maxWidth = '150px'; // '150px'
}
getValue(){
this.value = this.multipleSelect.getValueItems();
}
}
<ul class="multiple-select">
<li *ngFor="let item of items">
<div class="multiple-select-item">
<i *ngIf="item.items.length > 0" [ngClass]="{'i-expanded': item.expanded, 'i-collapsed': !item.expanded}"
(click)="item.expanded = !item.expanded"></i>
<label [ngClass]="{'margin-left-13': item.items.length == 0}">
<input type="checkbox" [(ngModel)]="item.checked" (ngModelChange)="item.checkChilds()" [disabled]="!item.enable" />
{{ item.text }}
</label>
</div>
<div *ngIf="item.expanded">
<tree-view [items]="item.items"></tree-view>
</div>
</li>
</ul>
<div class="multiple-selection" [style.width]="multipleSelect.maxWidth">
<button type="button" readonly (click)="dropdownToggle = !dropdownToggle">
<span>{{multipleSelect.selectionTitle }}</span>
<span class="i-down"></span>
</button>
<div class="show-tree-view" *ngIf="multipleSelect.items != undefined && dropdownToggle">
<div class="dropdown-header" *ngIf="multipleSelect.showHeader">
<label>
<input type="checkbox" [(ngModel)]="isCheckAll" (ngModelChange)="multipleSelect.checkAllItems(isCheckAll)" />
{{multipleSelect.checkAllCheckBoxText}}
</label>
<span [ngClass]="{'i-up': expanded, 'i-down': !expanded}" (click)="toggle()"></span>
</div>
<div class="tree-view-content" [style.max-height]="multipleSelect.maxHeight">
<tree-view [items]="multipleSelect.items" (change)="changeItems()"></tree-view>
</div>
</div>
</div>
multiple-select {
position: relative;
display: inline-block;
}
multiple-select input[type="checkbox"] {
margin: 0;
}
multiple-select button {
width: 100%;
height: 34px;
color: #333;
background-color: #fff;
border-color: #ccc;
padding: 5px 10px;
cursor: pointer;
background-image: none;
border: 1px solid #cccccc;
border-radius: 4px;
text-align: left;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
multiple-select button:hover {
-webkit-box-shadow: inset 0 3px 5px rgba(0, 0, 0, 0.125);
box-shadow: inset 0 3px 5px rgba(0, 0, 0, 0.125);
color: #333;
background-color: #e6e6e6;
border-color: #adadad;
}
multiple-select button:focus {
-webkit-box-shadow: inset 0 3px 5px rgba(0, 0, 0, 0.125);
box-shadow: inset 0 3px 5px rgba(0, 0, 0, 0.125);
color: #333;
background-color: #e6e6e6;
border-color: #8c8c8c;
}
multiple-select button .i-down {
float: right;
}
multiple-select .show-tree-view {
position: absolute;
top: 100%;
left: 0;
z-index: 1000;
float: left;
width: 100%;
margin: 0 -2px;
font-size: 14px;
text-align: left;
list-style: none;
background-color: #fff;
-webkit-background-clip: padding-box;
background-clip: padding-box;
border: 1px solid #ccc;
border: 1px solid rgba(0, 0, 0, 0.15);
border-radius: 4px;
-webkit-box-shadow: 0 6px 12px rgba(0, 0, 0, 0.175);
box-shadow: 0 6px 12px rgba(0, 0, 0, 0.175);
}
multiple-select .show-tree-view .tree-view-content {
display: inline-block;
width: 100%;
overflow: auto;
}
multiple-select .show-tree-view .dropdown-header {
border-bottom: 1px solid darkgray;
padding: 0 10px;
height: 25px;
line-height: 25px;
}
multiple-select .show-tree-view .dropdown-header label {
display: inline-block;
margin-bottom: 0;
}
multiple-select .show-tree-view .dropdown-header .i-up {
float: right;
}
multiple-select .show-tree-view .dropdown-header .i-down {
float: right;
}
multiple-select tree-view ul {
margin: 0 0 0 15px;
-webkit-margin-before: 0;
-webkit-margin-after: 0;
list-style-type: none;
padding: 0;
}
multiple-select tree-view .multiple-select-item {
display: flex;
}
multiple-select tree-view .multiple-select-item:hover {
background: aliceblue;
}
multiple-select tree-view .multiple-select-item .i-expanded {
cursor: pointer;
width: 0;
height: 0;
display: inline-block;
vertical-align: middle;
margin-right: 5px;
margin-top: 10px;
border-top: 4px dashed;
border-right: 4px solid transparent;
border-left: 4px solid transparent;
}
multiple-select tree-view .multiple-select-item .i-collapsed {
cursor: pointer;
width: 0;
height: 0;
display: inline-block;
vertical-align: middle;
margin-right: 9px;
margin-top: 9px;
border-left: 4px dashed;
border-top: 4px solid transparent;
border-bottom: 4px solid transparent;
}
multiple-select tree-view .multiple-select-item .margin-left-13 {
margin-left: 13px;
}
multiple-select .i-down {
cursor: pointer;
width: 0;
height: 0;
display: inline-block;
vertical-align: middle;
margin-top: 10px;
border-top: 4px dashed;
border-right: 4px solid transparent;
border-left: 4px solid transparent;
}
multiple-select .i-up {
cursor: pointer;
width: 0;
height: 0;
display: inline-block;
vertical-align: middle;
margin-top: 8px;
border-bottom: 4px dashed;
border-right: 4px solid transparent;
border-left: 4px solid transparent;
}