NileshPatel17 / ng-multiselect-dropdown

Multiple Select Dropdown Component
https://nileshpatel17.github.io/ng-multiselect-dropdown/
327 stars 287 forks source link

Need result by Ids list, not objects list #112

Open powermax01 opened 5 years ago

powermax01 commented 5 years ago

Hi, I am using this to select my Customers, having idField = 'id' and textField = 'name'. After the select values changed, I got a list of Customer objects but I expected a list of Customer Ids I can't see any setting to get that.

Please help.

NileshPatel17 commented 5 years ago

so, if you are getting list of customers, you can have ids list by using map function. hope this will help. const cusList=[{id:1,name:'Amol'},{id:2,'name:'Nilesh'}]; const cusIds=cusList.map(item=>item.id);

powermax01 commented 5 years ago

NileshPatel17, Thank you for your reply.

In my case I have a model as: model = { customerIds = []; ... } And the html is: <angular2-multiselect [data]="availableCustomers" [(ngModel)]="model.customerIds" ...>

as you can see, I am using model.customerIds as the model. Everytime the values changes, I get array of customer, but expected list of ids

I actually can use a array to store values: selectedCustomers then map to Ids list. But image, I have about 10 dropdowns in page. That means I must have 10 arrays for selected values, right? and I must map them to list of Ids. A lot of code added.

If it is possible, please have this option.

Thanks

craig-dae commented 5 years ago

I need this too. We are considering swapping out ngx-select-ex for this library, but we need an array of ids throughout our app, not an array of objects. This is the only thing stopping us from switching over.

rooby commented 4 years ago

I find it a bit strange that it doesn't return the ID or the actual object, but instead a made up stub that doesn't match anything else outside of the multiselect component. IT would be nice to have an option to choose between the current behaviour, return the full object, and return just the ID. Maybe even return just the text field, but I feel like there would be less use cases for that.