+ Start a Discussion
Mayank Singh DelhiMayank Singh Delhi 

Can some one please help me to get the Label name along with value attribute the Button menu with custom onselect handler... plz also note that I also tried event.detail.value gives me only value not the label.

User-added imageUser-added image
SwethaSwetha (Salesforce Developers) 
HI Mayank,
Your ask seems similar to https://salesforce.stackexchange.com/questions/278687/how-i-can-get-the-label-of-the-selected-value-in-combobox-lightning-web-compon/278691 which is in the context of combobox

"You do not have direct way of getting label (as you get only selected value in event.detail). You need to depend on all options (simply get it from event.target) and filter based on selected value. You can use below:
 
JS:
@track selectedLabel;

get options() {
    return [
        { label: 'New', value: 'new' },
        { label: 'In Progress', value: 'inProgress' },
        { label: 'Finished', value: 'finished' },
    ];
}

handleChange(event) {
    this.selectedLabel = event.target.options.find(opt => opt.value === event.detail.value).label;
}
 
HTML:
<lightning-combobox name="progress"
                        label="Status"
                        placeholder="Select Progress"
                        options={options}
                        onchange={handleChange}></lightning-combobox>

    <p>Selected label is: {selectedLabel}</p>

Hope this helps you. Please mark this answer as best so that others facing the same issue will find this information useful. Thank you
veer soniveer soni
Hi Mayank,
you should try following Code
<template>
    <div class="slds-p-around_medium lgc-bg">
        <lightning-button-menu alternative-text="Show menu" onselect={handelOnSelect}>
           <template for:each={lstButtonItem} for:item="btnItem">
            <lightning-menu-item key={btnItem.value} value={btnItem.value}
             label={btnItem.label}>
            </lightning-menu-item>
            </template>
         
    </lightning-button-menu>
        </div>
</template>
 
import { LightningElement } from 'lwc';

export default class ButtonMenuOnSelect extends LightningElement {
    lstButtonItem = [
{value:"MenuItemOne", label:"Menu Item One"},
{value:"MenuItemTwo", label:"Menu Item Two"},
{value:"MenuItemThree", label:"Menu Item Three"},
{value:"MenuItemFour", label:"Menu Item Four"}
];
    handelOnSelect(event){
       var getValue = event.detail.value;
      
       let selectButtonItem = this.lstButtonItem.find(item => item.value == getValue );
       alert(selectButtonItem.label);
      
    }

}


If it's help you, Please Best Mark so that it help others

Thank You

Mayank Singh DelhiMayank Singh Delhi
Thanks Swetha & Veer for your quick response which I really appreciate. But in both the ways my problem is not getting solved. As I need the id of the clicked record as value while label is fine here. I have attatched the snapshot of the requirement. Please help me. I am new in LWC and so difficult to related the things. Thanks for all your efforts till now.!! It is very urget...User-added image
veer soniveer soni

Hello mayank,
I saw your snapshot, I think you want ID when you click on approve OR Reject Button-Menu.

But your data-key's row-id   id   In small Letter And your lightning-menu-item's value's {row.Id}  Id is Capital

data-key={row.id}   AND value={row.Id}  Both are  Different,Once you should check your code and try again.
 

Mayank Singh DelhiMayank Singh Delhi
Hi Veer,
You got my point now. code in the above screesho is working fine and i'm able to get the value as ID as well but not the lebel. However,                                                                  User-added image                                                                                 by your approach I am able to get value but in string type and label too. Is it possible i could get value as ID. Hope you understand.                                                                                      
veer soniveer soni

Hi Mayank,

You should aply this following Method in your apex Class,If you are using apex in your requirment.

String a = '0035g000002J68LAAS';
Id i = Id.valueOf(a);
system.debug(i);


this Method is convert string into Id

If This time your requirment is not complete then plz show your complete code Like HTML,JS And Apex.
I will try to Fix Your Issue.

Thank You Mayank