BoldSignA modern eSignature application with affordable pricing. Sign up today for unlimited document usage!
Hello, I am trying to get dynamic data into a dropdown for a grid column that is multiselect.
I borrowed the implementation of a multi select dropwdown from here:
https://stackblitz.com/edit/angular-bda4p5-5wesng?file=app.component.ts
And I had help before with a normal dropdown in a grid when setting an external dynamic data source:
https://www.syncfusion.com/forums/178743/dropdown-edit-observable-list
But I am unable to combine the two ideas together:
My code might be a mess, but maybe you could demonstrate the right approach to having dynamic data in a multi-select dropdown.
Thank you for your help in advance!
Hi Frank,
Thanks for contacting Syncfusion support.
When using cellEditTemplate feature, we can’t use the column.edit.params to customize the properties of edit component. We suggest you to bind the dynamic data directly to the variable and access it inside the write method.
this.editparams = { create: () => { this.elem = document.createElement('input'); return this.elem; }, read: () => { return this.multiSelectObj.value.join(','); }, destroy: () => { this.multiSelectObj.destroy(); }, write: (args) => { var cellvalue = args.rowData[args.column.field].split(','); this.multiSelectObj = new MultiSelect({ //set the data to dataSource property dataSource: this.multiselectDatasource, value: cellvalue, fields: { text: 'ShipCountry', value: 'ShipCountry' }, floatLabelType: 'Never', mode: 'Box', }); this.multiSelectObj.appendTo(this.elem); }, }; const ajax = new Ajax( 'https://ej2services.syncfusion.com/production/web-services/api/Orders', 'GET' ); ajax.send(); ajax.onSuccess = (data) => { var result = JSON.parse(data); this.multiselectDatasource = new DataManager(result); }; }
|
Sample: https://stackblitz.com/edit/angular-jgtwac-frnf3a?file=app.component.html,app.component.ts
Regards,
Rajapandiyan S
Thank you so much Rajapandiyan, maybe as a side note you could assist me in making the search in this dropdown do "contains instead of begins with?
Hi Frank,
Based on your requirement you want to search the value with contains operator in the MultiSelect component. You can achieve this by using the filtering event of MultiSelect.
Filtering: https://ej2.syncfusion.com/documentation/multi-select/filtering/#change-the-filter-type
//set the data to dataSource property dataSource: this.multiselectDatasource, value: cellvalue, fields: { text: 'ShipCountry', value: 'ShipCountry' }, floatLabelType: 'Never', allowFiltering: true, //Bind the filter event filtering: (e) => { let query = new Query(); //frame the query based on search string with filter type. query = e.text != '' ? query.where('ShipCountry', 'contains', e.text, true) : query; var filteredData = new DataManager(this.multiSelectObj.dataSource).executeLocal(query); //pass the filtered data source. e.updateData(filteredData); }, mode: 'Box', });
|
Sample: https://stackblitz.com/edit/angular-jgtwac-3r112y?file=app.component.ts
Regards,
Rajapandiyan S