function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
MOHAMMED BABAMOHAMMED BABA 

How to use info-button or onhover inside the data table of lwc component

I am using below code I want to display Info button or onhover on one of the custom field inside the lwc data table but not able to achieve this ,kindly guide me <template>
    <div class="slds-m-around_x-small">
        <lightning-card title="Connect With Stackholders" icon-name="standard:channel_program_history">
            <lightning-layout multiple-rows>
                <lightning-layout-item size="12" small-device-size="3" medium-device-size="3" large-device-size="3"
                    padding="around-small">
                    <lightning-combobox class="priorityAlign" label="Risk Id" name="input2"
                        placeholder={selectDepartment} options={riskIdsBasedOnRegion} dropdown-alignment="auto"
                        onchange={handleChangeRiskId}></lightning-combobox>
                </lightning-layout-item>
                <lightning-layout-item size="12" small-device-size="2" medium-device-size="2" large-device-size="2"
                    padding="around-small">
                    <lightning-input label="Risk Name" type="text" value={riskNameValue} autocomplete="off" disabled></lightning-input>
                </lightning-layout-item>

                <lightning-layout-item size="12" small-device-size="2" medium-device-size="2" large-device-size="2"
                    padding="around-small">
                    <lightning-input label="Region" type="text" value={regionValue} disabled></lightning-input>
                </lightning-layout-item>
                <lightning-layout-item size="12" small-device-size="3" medium-device-size="3" large-device-size="3"
                    padding="around-small">
                    <lightning-dual-listbox class="priorityAlign" label="Department" name="input2"
                        placeholder={selectDepartment} options={listOfDepartment} dropdown-alignment="auto"
                        onchange={handleChangeDepartment}></lightning-dual-listbox>
                </lightning-layout-item>

                <lightning-layout-item size="12" small-device-size="2" medium-device-size="2" large-device-size="2"
                    padding="around-small">
                    <div class="slds-m-top_large">
                        <lightning-button variant="success" label="Submit" onclick={handleSave}></lightning-button>
                    </div>
                   
                </lightning-layout-item>
            </lightning-layout>
           
       
    </lightning-card>
</div>
       
    <template if:true={dataTableValue}>
        <lightning-datatable data={dataTableValue} columns={columns} key-field="Id" hide-checkbox-column
            aria-selected="true" onsave={handleSaveDataTable} draft-values={saveDraftValue}
            onrowaction={handleRowAction}>
            <template for:each={dataTableValue} for:item="record">
                <tr key={record.Id}>
                    <!-- ... Other columns ... -->
                    <td data-label="Total Financial Impact" onmouseover={showValue} onmouseout={hideValue}>
                        <template if:true={record.Total_Financial_Impact__c}>
                            <div class="value-container">
                                {record.Total_Financial_Impact__c}
                                <div class="info-button" data-id={record.Id} onclick={showInfo}>i</div>
                                <template if:true={shouldRenderInfo}>
                                    <div class="info-tooltip">Total: {calculatedTotalFinancialImpact}</div>
                                </template>
                            </div>
                        </template>
                        <template if:false={record.Total_Financial_Impact__c}>
                            <div class="value-container">
                                {record.Total_Financial_Amount__c}
                            </div>
                        </template>
                    </td>
                </tr>
            </template>
        </lightning-datatable>
    </template>
   
</template>
 @track showTooltip = false;
    @track selectedRecordId = null;
    @track totalFinancialImpact = 0;
    get shouldRenderInfo() {
        return this.selectedRecordId !== null;
    }
    get calculatedTotalFinancialImpact() {
        if (this.dataTableValue && this.dataTableValue.length > 0) {
            this.totalFinancialImpact = this.dataTableValue.reduce(
                (sum, record) => sum + record.Total_Financial_Impact__c,
                0
            );
        } else {
            this.totalFinancialImpact = 0;
        }
        return this.totalFinancialImpact;
    }
    // ... other methods ...
    // Update the showValue and showInfo methods to handle the tooltip display
    showValue(event) {
        const recordId = event.target.dataset.id;
        this.selectedRecordId = recordId;
        this.showTooltip = true;
    }
    showInfo(event) {
        const recordId = event.target.dataset.id;
        this.selectedRecordId = recordId;
        this.showTooltip = true;
    }
    hideValue() {
        this.selectedRecordId = null;
        this.showTooltip = false;
    }   
AshwiniAshwini (Salesforce Developers) 
Hi @MOHAMMED BABA,

There could be issues with the way the 'Info' button and tooltip are displayed, which could be caused by problems with HTML elements and JavaScript.  Make sure that these components are correctly linked and styled to make the tooltip display correctly.

Make sure that the data-id attribute is correctly used to identify the record, and check for any errors in the browser's developer console.

If this information helps, please mark the answer as best. Thank you

 
MOHAMMED BABAMOHAMMED BABA
Hi @Ashwini thank you for your quick response.
is there any example code or is it possible using in the lwc data table that we can display info button on each record , if you have any document it would be more helpful