Hi, I hope you can assist me with this : I added a custom field, a dropdown list called 'Client', and I want to populate that with dynamic data (clients) from my MongoDB. This is my code:
onPopupOpen(args: PopupOpenEventArgs): void {
if (args.type === 'Editor') {
// Create required custom elements in initial time
if (!args.element.querySelector('.custom-field-row')) {let row: HTMLElement = createElement('div', {className: 'custom-field-row'});
let formElement: HTMLElement = args.element.querySelector('.e-schedule-form');
formElement.firstChild.insertBefore(row, args.element.querySelector('.e-title-location-row'));
let container: HTMLElement = createElement('div', {className: 'custom-field-container'});
let inputEle: HTMLInputElement = createElement('input', {
className: 'e-field', attrs: {name: 'Klant'}
}) as HTMLInputElement;container.appendChild(inputEle);row.appendChild(container);let dropDownList: DropDownList = new DropDownList({
dataSource: [
this.Client.map(client => ({text: client.company, value: client.company})),
],
fields: {text: 'text', value: 'value'},
value: (<{ [key: string]: Object }>(args.data)).Client as string,
floatLabelType: 'Always', placeholder: 'Client'
});}}dropDownList.appendTo(inputEle);
inputEle.setAttribute('name', 'Client');This is giving me an empty dropdown list. Why isnt it showing all the clients of the logged in user? So I want to display the
companyproperty of every client (Object). When I try to statically show the client of the first element, like this, it works. But i want it to be dynamic, because every user has a different amount of clients.dataSource: [
{text: this.clients[0].company, value: this.clients[0].company},
],If you need more info, please let me know.
This is where I retrieve the response of the clients:
ngOnInit() {
this.clientService.getClients().subscribe((data : any) => {
this.clients= data.client;
});
console.log(this.clients)
}
|
ngOnInit(): void {
this.selectedDate = new Date(2018, 1, 14);
this.eventSettings = { dataSource: this.dataManager };
const studentsObservable = this.scheduleService.getSchedule();
studentsObservable.subscribe((dropDowmData: Schedule[]) => {
this.dropDownDataSource = dropDowmData;
});
}
onPopupOpen(args: PopupOpenEventArgs): void {
if (args.type === 'Editor') {
// Create required custom elements in initial time
if (!args.element.querySelector('.custom-field-row')) {
let row: HTMLElement = createElement('div', { className: 'custom-field-row' });
let formElement: HTMLElement = <HTMLElement>args.element.querySelector('.e-schedule-form');
formElement.firstChild.insertBefore(row, args.element.querySelector('.e-title-location-row'));
let container: HTMLElement = createElement('div', { className: 'custom-field-container' });
let inputEle: HTMLInputElement = createElement('input', {
className: 'e-field', attrs: { name: 'EventType' }
}) as HTMLInputElement;
container.appendChild(inputEle);
row.appendChild(container);
let drowDownList: DropDownList = new DropDownList({
dataSource: this.dropDownDataSource,
fields: { text: 'text', value: 'value' },
value: (args.data as { [key: string]: Object }).EventType as string,
floatLabelType: 'Always', placeholder: 'Event Type'
});
drowDownList.appendTo(inputEle);
inputEle.setAttribute('name', 'EventType');
}
}
} |
this.clientService.getClients().subscribe((data : any) => {
this.clients = data.client;
});
I want the Dropdownlist as follows: (but in this case the DropDownlist is empty.
dataSource: [
this.clients.map(client => ({text: client.company, value: client.company})),
],
|
ngOnInit(): void {
this.selectedDate = new Date(2018, 1, 14);
this.eventSettings = { dataSource: this.dataManager };
const clientObservable = this.clientService.getClient();
clientObservable.subscribe((client: client[]) => {
this.dropDownDataSource = client;
});
}
onPopupOpen(args: PopupOpenEventArgs): void {
if (args.type === 'Editor') {
// Create required custom elements in initial time
if (!args.element.querySelector('.custom-field-row')) {
let row: HTMLElement = createElement('div', { className: 'custom-field-row' });
let formElement: HTMLElement = <HTMLElement>args.element.querySelector('.e-schedule-form');
formElement.firstChild.insertBefore(row, args.element.querySelector('.e-title-location-row'));
let container: HTMLElement = createElement('div', { className: 'custom-field-container' });
let inputEle: HTMLInputElement = createElement('input', {
className: 'e-field', attrs: { name: 'EventType' }
}) as HTMLInputElement;
container.appendChild(inputEle);
row.appendChild(container);
let drowDownList: DropDownList = new DropDownList({
dataSource: this.dropDownDataSource,
fields: { text: 'company', value: 'companyValue' },
value: (args.data as { [key: string]: Object }).EventType as string,
floatLabelType: 'Always', placeholder: 'Event Type'
});
drowDownList.appendTo(inputEle);
inputEle.setAttribute('name', 'EventType');
}
}
} |