| ... import { GridComponent ,IEditCell, EditService, ToolbarService, EditSettingsModel, ToolbarItems, Column} from '@syncfusion/ej2-ng-grids'; import { DropDownList, MultiSelect, CheckBoxSelection } from '@syncfusion/ej2-dropdowns'; ... MultiSelect.Inject(CheckBoxSelection); @Component({ selector: 'app-root', template: `<ejs-grid [dataSource]='data' allowEditing='true' allowPaging='true' [editSettings]='editSettings' [toolbar]='toolbar'> <e-columns> <e-column field='EmployeeID' headerText='EmployeeID' width='120' textAlign='Right' isPrimaryKey='true' [validationRules]='orderidrules'></e-column> <e-column field='categories' headerText='categories' width='120' [valueAccessor]='valueAccess' [edit] ='dpParams' ></e-column> <e-column field='City' headerText='City' width='120' textAlign='Right'></e-column> </e-columns> </ejs-grid>`, styleUrls: ['./app.component.css'] }) export class AppComponent { public data: Object[]; public editSettings: Object; public elem: HTMLElement; public dpParams: IEditCell; public dropdownObj: DropDownList; public msObject: MultiSelect; public toolbar: string[]; public dropdownData = [{ //dataSource for the multiselect dropdown "categories": ["Clothing","Electronics","Electricals","Furniture","Outdoors"] }]; public valueAccess = (field: string, data: Object, column: Object) => { return data['categories']; //to bind the data to the categories column } ngOnInit(): void { this.data = stringData; this.editSettings = { allowEditing: true, allowAdding: true, allowDeleting: true }; this.toolbar = ['Add', 'Edit', 'Delete', 'Update', 'Cancel']; this.dpParams = { create: () => { this.elem = document.createElement('input'); return this.elem; }, read: () => { return this.msObject.value; }, destroy: () => { this.msObject.destroy(); }, write: (args: any) => { this.msObject = new MultiSelect({ // bind the dropdownData to datasource property dataSource: this.dropdownData[0].categories, //set the placeholder to MultiSelect input placeholder:"Select categories", // set the type of mode for checkbox to visualized the checkbox added in li element. mode: 'CheckBox', value: args.rowData['categories'] }); //render the component this.msObject.appendTo(this.elem); } } } } |
|
ngOnInit(): void {
...
this.dpParams = {
create: () => {
this.elem = document.createElement('input');
return this.elem;
},
read: () => {
return this.multiSelectObj.value;
},
destroy: () => {
this.multiSelectObj.destroy();
},
write: (args) => {
this.multiSelectObj = new MultiSelect({
dataSource: this.multiSelectData,
popupHeight: '200px',
fields: { value: 'ShipCountry', text: 'ShipCountry' },
placeholder: 'Ship Country',
mode: 'CheckBox',
});
this.multiSelectObj.appendTo(this.elem);
}
};
}
}
|
|
...
ngOnInit(): void {
this.data = orderDataSource;
this.pageSettings = { pageCount: 5 };
this.filterSettings = { type: 'Menu' };
this.city = ["Denmark", "Brazil", "Germany", "France", "Belgium"];
this.multiSelectData = [
{ sid: '1', ShipCountry: 'Denmark' },
{ sid: '2', ShipCountry: 'Brazil' },
{ sid: '3', ShipCountry: 'Germany' },
{ sid: '4', ShipCountry: 'France' },
{ sid: '5', ShipCountry: 'Belgium' },
];
...
this.dpParams = {
create: () => {
this.elem = document.createElement('input');
return this.elem;
},
read: () => {
return this.multiSelectObj.value;
},
destroy: () => {
this.multiSelectObj.destroy();
},
write: (args) => {
this.multiSelectObj = new MultiSelect({
dataSource: this.multiSelectData,
popupHeight: '200px',
fields: { value: 'ShipCountry', text: 'ShipCountry' },
placeholder: 'Ship Country',
mode: 'CheckBox',
});
this.multiSelectObj.appendTo(this.elem);
}
};
}
} |