CuppaLabs / angular2-multiselect-dropdown

Angular 2 Dropdown Multiselect
https://cuppalabs.github.io/angular2-multiselect-dropdown
MIT License
291 stars 256 forks source link

SelectedItems with primaryKey field only #404

Open anikets43 opened 5 years ago

anikets43 commented 5 years ago

We usually store only ids/value field in the DB for dropdown items. While fetching the record, we have only list of selected ids/value i.e. ['Singapore', 'India'] instead of array of objects.

It would be good to have this feature where developer don't have to manipulate the data for to pre-populate the selectedItems

this.dropdownList = [
      { "id": 1, "name": "India" },
      { "id": 2, "name": "Singapore" },
      { "id": 3, "name": "Australia" },
      { "id": 4, "name": "Canada" },
      { "id": 5, "name": "South Korea" },
      { "id": 6, "name": "Brazil" }
    ];

// Should allow selected items to be only array of primarykey
//  this.selectedItems = [ 'India', 'Singapore', 'Australia']; 

this.selectedItems = [
      { "id": 1, "name": "India" },
      { "id": 2, "name": "Singapore" }];

this.settings = {
      text: "Select Countries",
      selectAllText: 'Select All',
      unSelectAllText: 'UnSelect All',
      primaryKey: 'name',
      labelKey: 'name',
    };

https://stackblitz.com/edit/angular2-multiselect-dropdown-bug-sbzntx

cciccole commented 5 years ago

+1

I'll add that it's not clear to me what the purpose of primaryKey is

CuppaLabs commented 5 years ago

primaryKey is to make the dropdown identify the list items by unique property name, which is different for different data sets and users. The feature is already available. Please check 'primaryKey' in settings.

cciccole commented 5 years ago

@CuppaLabs this is not working correctly and shouldn't be closed.

If you do believe it is working correctly, could you fix this stackblitz (https://stackblitz.com/edit/angular2-multiselect-dropdown-bug-ng4bsf)? The desired behavior is that an array of names should print to the console upon selection instead of an array of objects.

CuppaLabs commented 5 years ago

@cciccole The events will only return objects... Please not that further manipulation of the object you need to take care in the callback methods. So cannot give it as component feature.

cciccole commented 5 years ago

@CuppaLabs I'm fine with the events only returning objects. We're only using events in the stackblitz example such that we can print the ngModel array. Data binding is what this request is about.

To be clear, the request at hand is that we can accomplish data binding with an attribute of the objects in the multiselect-dropdown and not just with the objects themselves.

If you consider anikets43 example closely, the desired behavior is that this.selectedItems should be an array of names and not an array of objects. The stackblitz I shared with you indicates that this is not possible.

This is a functionality found in other multiselect dropdown components (exact example here) but not in angular2-multiselect-dropdown. Maybe I'm wrong, but it doesn't seem like you are quite understanding our request.

Let me know if this clarification helps, and if you think it's reasonable to support this request.

CuppaLabs commented 5 years ago

@cciccole You are correct ! This is a reasonable good ask. Let me take this up for next release

AbdealiLoKo commented 5 years ago

For what it's worth, i was looking for the same thing and came across this. Is there any planned timeline for the next release / for this feature ? I do see a 4.5 that came out recently, but guessing this is not solved there

gethari commented 4 years ago

Ah here I am 2 Years later, is this available ? Or is there a timeline ?