DEV Community

Maik Michel
Maik Michel

Posted on • Originally published at micodify.de on

Highlight current row

In many applications I build, I use modal dialogs for the actual transaction. This is how the actual data records are processed. The user himself usually opens the dialog with a link. This is often found as a link in a classic report. As soon as the user clicks on this link, he can edit the corresponding content. From a UI/UX perspective, the reference to the clicked content is lost. Due to the shift in focus, it is usually difficult or even impossible to see to which data set the opened dialog actually belongs.

For this reason I mark the corresponding line with the focus. The event onfocus is triggered by the actual click on the button/link or by using the keyboard.

So first we need the function that marks the line for us:

function highlightRow(link) {  
  // remove old highlighted rows
  document.querySelectorAll("table tr.highlighted-row").forEach((elem) => {
    elem.classList.remove('highlighted-row');
  });

  // add class to tr
  link.parentNode.parentNode.classList.add('highlighted-row');
}
Enter fullscreen mode Exit fullscreen mode

Afterwards, we build them into the attribute field of the actual link in the Classic Report:

So that the clicked record also colors itself, we define here still another brighter version of the primary color and a class, which uses this as background color as well.

Done, now as soon as the link is clicked, the corresponding line is highlighted.

Take a look at the demo application.

AWS GenAI LIVE image

Real challenges. Real solutions. Real talk.

From technical discussions to philosophical debates, AWS and AWS Partners examine the impact and evolution of gen AI.

Learn more

Top comments (0)

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay