|
@Component({
selector: 'app-container',
// specifies the template string for the DropDownList component with change event
template: `<ej-dropdownlist id='ddlelement' #samples [dataSource]='data' [fields]='fields' [placeholder]='text' [query]='query' [sortOrder]='sorting'
[value] = 'value'></ej-dropdownlist>`
})
export class AppComponent {
constructor() {
}
//bind the DataManager instance to dataSource property
public data: DataManager = new DataManager({
url: 'http://services.odata.org/V4/Northwind/Northwind.svc/',
adaptor: new ODataV4Adaptor,
crossDomain: true
});
// maps the appropriate column to fields property
public fields: Object = { text: 'ContactName', value: 'CustomerID' };
//bind the Query instance to query property
public query: Query = new Query().from('Customers').select(['ContactName', 'CustomerID']).take(6),
//set the placeholder to DropDownList input
public text: string = "Select a customer";
//sort the result items
public sorting: string = 'Ascending';
// set the value in dropdownlist
public value: string = 'ALFKI';
}
|
|
@Component({
selector: 'app-container',
// specifies the template string for the MultiSelect component
template: `<ejs-multiselect id='multiselectelement' #multiselectelement [dataSource]='data' [fields]='fields' [placeholder]='placeholder' [query]='query' [sortOrder]='sorting' [value]='value'></ejs-multiselect>`
})
export class AppComponent {
constructor() {
}
ngAfterViewInit() {
// Set null value to value property for clear the selected item
document.getElementById('btn').onclick = () => {
this.multiSelectObject.dataSource = [
{ id: 'Game1', sports: 'Badminton' },
{ id: 'Game2', sports: 'Basketball' },
{ id: 'Game3', sports: 'Cricket' },
{ id: 'Game4', sports: 'Football' },
{ id: 'Game5', sports: 'Golf' }
];
// maps the appropriate column to fields property
this.multiSelectObject.fields = { text: 'sports', value: 'id' };
//bind the Query instance to query property
this.multiSelectObject.query = new Query().take(5);
// set the value
this.multiSelectObject.value = ['Game2'];
}
}
//bind the DataManager instance to dataSource property
public data: DataManager = new DataManager({
url: 'http://services.odata.org/V4/Northwind/Northwind.svc/',
adaptor: new ODataV4Adaptor,
crossDomain: true
});
// maps the appropriate column to fields property
public fields: Object = { text: 'ContactName', value: 'CustomerID' };
//bind the Query instance to query property
public query: Query = new Query().from('Customers').select(['ContactName', 'CustomerID']).take(5);
// set placeholder to MultiSelect input element
public placeholder: string = 'Select customers';
//sort the result items
public sorting: string = 'Ascending';
// set the value
public value:sting[] = ['ALFKI'];
@ViewChild('multiselectelement')
public multiSelectObject: MultiSelectComponent;
} |
|
@Component({
selector: 'my-app',
template: `<div id='targetElement'>
<table cellpadding="2" cellspacing="0" border="1" width="50%">
<tr>
<th>
<div>
<input value="Data"/>
</div>
</th>
</tr>
<tr>
<td>
<div>
<input (keydown)="alertBtnClick($event)" value="Basketball"/>
</div>
</td>
</tr>
<tr>
<td>
<div>
<input (keydown)="alertBtnClick($event)" value="Cricket"/>
</div>
</td>
</tr>
</table>
<button ejs-button class='dlgbtn' id='alertbtn' #alertButton (click)="alertBtnClick()">Alert</button>
<ejs-dialog #alertDialog [visible]='hidden' [header]='alertHeader' [animationSettings]='animationSettings' [content]='alertContent' [showCloseIcon]='showCloseIcon' (open)="dialogOpen()" (close)="dialogClose()" [target]='target'
[width]='alertWidth'>
</ejs-dialog></div>`,
// include the material theme to AutoComplete
styleUrls: ['../../node_modules/@syncfusion/ej2-dropdowns/styles/material.css',
'../../node_modules/@syncfusion/ej2-popups/styles/material.css'],
encapsulation: ViewEncapsulation.None
})
export class AppComponent {
public alertHeader: string = 'Low Battery'; //dialog header
public alertContent: string = '<div id=dropdownist></div>'; // multiselct
public hidden: Boolean = false;
public alertWidth: string = '250px';
public showCloseIcon: Boolean = false;
public animationSettings: Object = { effect: 'None' };
public hide:any;
public alertDlgButtons: Object[] = [{ click: this.alertDlgBtnClick, buttonModel: { content: 'Dismiss', isPrimary: true } }]; //it is for button if you want use a button to show the dialog with multiselect
@ViewChild('alertDialog')
public alertDialog: DialogComponent;
public listObj: MultiSelect = new MultiSelect({
// set the placeholder to MultiSelect input element
placeholder: 'Favorite Sports',
// set the type of mode for how to visualized the selected items in input element.
mode: 'Box',
dataSource: ["Basketball","Cricket"]
});
alertDlgBtnClick() {
this.hide();
}
alertBtnClick(args :any) {
this.listObj.value=[args.currentTarget.defaultValue];
this.listObj.appendTo("#dropdownist"); //multiselect append to the dialog
this.alertDialog.show();
this.dialogOpen();
}
// On Dialog close, show the buttons
//
} |