Hi Guys,
Once again this just might be me not understanding some basics. But I am trying to figure out how to take an observable value and use it as a datasource in dropdown column edit.
I started off with this example and it works fine with static data:
https://ej2.syncfusion.com/angular/documentation/grid/editing/edit-types/#provide-custom-data-source-and-enabling-filtering-to-dropdownlist
But I would like to call
getUsers()
observable result instead of static data and of course because they are both on the ngOnInit means that my
this.users = value;
gets resolved last after
this.userParams has already been set with the static data. Now if I put the whole
this.userParams
inside subscribe well then it wont be defined as well when the component initializes. Could you potentially point me in the right direction? I am highly confused about this one.
----
Hi Frank Alberts,
Thanks for contacting Syncfusion support.
You can set the DropDownList dataSource inside the service by accessing the grid column directly. Please refer to the below code example and the sample link for more information.
this.service.getData({}).subscribe((value: any) => { this.grid.columns[2].edit.params.dataSource = value.result; });
|
Sample: https://stackblitz.com/edit/angular-7c8www?file=app%2Fapp.module.ts,app.component.ts
Please get back to us if you need further assistance on this.
Regards,
Pavithra S
Hi Pavithra,
I am getting this error on .edit and I am unsure what is causing it. Located on this line this.routeGrid.columns[1].edit.params.dataSource = value.result;
Property 'edit' does not exist on type 'string | Column | ColumnModel'.
Property 'edit' does not exist on type 'string'.
You can overcome the Type error by setting the type for the grid column as in the below code example.
import { DropDownListModel } from '@syncfusion/ej2-dropdowns'; import { Column } from '@syncfusion/ej2-grids';
. . .
((this.routeGrid.columns[1] as Column).edit.params as DropDownListModel).dataSource = [];
|
Hi Pavithra Subramaniyam,
Just something to note in the end I had to do this otherwise it was expecting a boolean for some reason.
((this.routeGrid.columns[1] as Column).edit.params as DropDownListModel).dataSource = new DataManager(this.users);
But Thank you it finally works!!! I am very happy!
Welcome!
We are happy to hear that you have resolved the issue. Please get back to us if you need further assistance on this.