Primeng: dataKey property for dropdown list

Created on 3 Jul 2017  路  5Comments  路  Source: primefaces/primeng

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>

Most helpful comment

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?

All 5 comments

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.

Seems it already has it.

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 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?

Hello,

wrote a possible solution to this open issue:
#7704

Greetings
tobibe

Was this page helpful?
0 / 5 - 0 ratings