Jump to content

Recommended Posts

Hello,

I have a DataPage that uses this code in the Footer:

<script>

document.querySelectorAll(`[action*="[@cbAppKey]"] td:nth-child(2)`).forEach(function(elem) {
 if(elem.innerHTML > 0)  elem.style.textDecoration = "line-through";
})
document.querySelectorAll(`[action*="[@cbAppKey]"] td:nth-child(3)`).forEach(function(elem) {
 if(elem.innerHTML > 0)  elem.style.textDecoration = "line-through";
})

document.querySelectorAll(`[action*="[@cbAppKey]"] td:nth-child(2)`).forEach(function(elem) {
 if(elem.innerHTML <= 0 ) elem.style.textDecoration = "none";
})
document.querySelectorAll(`[action*="[@cbAppKey]"] td:nth-child(3)`).forEach(function(elem) {
 if(elem.innerHTML <= 0 ) elem.style.textDecoration = "none";
})

</script>

This code is used for having the data with line-through if the number is greater than 0. However, even though I input additional column such as the Calculated Field below, it would not show. It seems the code is only used for numbers and not on currency, text or other datatype. I also tried this code but no luck:

<script>
var elems = document.getElementsByTagName("td");
for (var i=0, m=elems.length; i<m; i++) {
if (elems[i].innerHTML>0)
  { elems[i].style.textDecoration = "line-through";}
}
</script>

Result:

image.thumb.png.8ec46df0ccc66a03b60d82e71e4e3753.png

What am I missing? I also wanted it to put line through in Text and currency datatypes? Should I convert it? Thanks!

Link to post
Share on other sites

Hi @JanineB,

It looks like the "$" currency sign added by formatting is the reason for element value not been recognized as a number.

You may add a replace function with regex to remove unwanted characters from value formatted as currency.

So, your JavaScript would look like this:

<script>
  
var elems = document.getElementsByTagName("td");
  
for (var i=0, m=elems.length; i<m; i++) {
  
if (elems[i].innerHTML.replace(/[^0-9\.-]+/g,"") > 0) { 
  
    elems[i].style.textDecoration = "line-through";

    }
  
}
</script>

Regards,

vitalikssssss

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...