primeng icon indicating copy to clipboard operation
primeng copied to clipboard

dataKey property for dropdown list

Open gtzinos opened this issue 9 years ago • 5 comments

Hi, I am searching in documentation but i can't find an example with a dataKey in a dropdown list. My objects have a different key from your default name 'value' so i am trying to use dataKey in order to use this custom key name.

I need something like this but it doesn't work:

<p-dropdown (onChange)="doSomething($event)" dataKey="{{ifTrue ? 'key1' : 'key2}}" [options]="arrayObj">
            <ng-template let-option pTemplate="item">
                <div>
                    <div>{{option.label ? option.label : option}}</div>
                </div>
            </ng-template>
</p-dropdown>

gtzinos avatar Jul 03 '17 10:07 gtzinos

dataKey is used for faster equality checks, we can add it but not sure that would help your case which is not clear to me.

cagataycivici avatar Aug 23 '17 07:08 cagataycivici

Seems it already has it.

cagataycivici avatar Sep 12 '17 08:09 cagataycivici

I'm commenting here but maybe I need a separate issue?

In fact, I wanted a dropdown that does not select the option Object as value but the dataKey as value.

So instead of having {code:'UK', label: 'United Kingdom'} as value I'd want 'UK' (with dataKey="code").

Would this be possible?

beaumkr avatar Mar 20 '18 12:03 beaumkr

@beaumkr I have the same problem with you. I have array and objects inside of it like this,

[
{
  name: 'Recep',
  username: 'recepcan'
}
]

I want to display 'name' key with optionLabel I want to set model username key with dataKey, is this possible?

rewebcan avatar Apr 13 '18 12:04 rewebcan

Hello,

wrote a possible solution to this open issue: #7704

Greetings tobibe

tobibe avatar Sep 13 '19 22:09 tobibe