0

I am new to LWC, so looking for some help over here related to one scenario. I am using lightning-datatable to show set of records on the page where one column field to be displayed as masked field like "*****57463" and when we hover on that field we need to show full value such as 1234657463. I havent coded yet looking for suggestion like is it possible with lightning-datatable or not. If yes please guide me.

If not then alternative solution will be using table and loop the records and on that column value will be using other component to display masked value and on hover display full value on the column.

Thanks in advance.

1
  • just wondering why would you want to do the above? since hovering over is going to show the full value either way? you might as well leave it as it is, to save the user from hovering over to see the value but on the other side, you can look into using static resources for standard lightning-datatable, I have not modified lightning-datatable using static resource much. However, you can achieve it using standard html table and onmouseover event.
    – prem22
    Commented Jul 9, 2023 at 17:18

1 Answer 1

0

This can be achieved by html table and css:

In the JavaScript file, setup the records list by creating a maskedValue property something like below:

  records = [
    {
      maskedField: {
        value: '12345678',
        maskedValue: '******78'
      },
      //..other properties
    },
    {
      maskedField: {
        value: 'abcdefgh',
        maskedValue: '******gh'
      },
      //..other properties
    },
    //..other records
  ];

In the HTML, create a table and loop through the records and add both masked and unmasked values.

  <table>
    <!--thead></thead-->
    <tbody>
      <template for:each={records} for:item="record">
        <tr key={index}>
          <td>
            <div class="has-masked-field">
              <span class="non-masked-value">{record.maskedField.value}</span>
              <span class="masked-value">{record.maskedField.maskedValue}</span>
            </div>
          </td>
        </tr>
      </template>
    </tbody>
  </table>

In the CSS, hide the masked-value by default. On hover hide the masked-value and show the non-masked-value.

.has-masked-field .non-masked-value {
  display: none;
}

.has-masked-field:hover .masked-value {
  display: none;
}
.has-masked-field:hover .non-masked-value {
  display: initial;
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .