angular2-multiselect-dropdown icon indicating copy to clipboard operation
angular2-multiselect-dropdown copied to clipboard

SelectedItems with primaryKey field only

Open anikets43 opened this issue 5 years ago • 8 comments

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

anikets43 avatar Jul 10 '19 08:07 anikets43

+1

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

cciccole avatar Aug 04 '19 10:08 cciccole

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.

CuppaLabs avatar Aug 04 '19 10:08 CuppaLabs

@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.

cciccole avatar Aug 04 '19 10:08 cciccole

@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.

CuppaLabs avatar Aug 04 '19 11:08 CuppaLabs

@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.

cciccole avatar Aug 05 '19 01:08 cciccole

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

CuppaLabs avatar Aug 05 '19 17:08 CuppaLabs

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

AbdealiLoKo avatar Sep 05 '19 17:09 AbdealiLoKo

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

gethari avatar Jul 02 '20 05:07 gethari