Jump to content

0-100 Progress bar on tabular report


Recommended Posts

Hi there,

For one of my projects, I needed to display 0-100 values in one of the fileds on tabular report in a form of a progress bar.
Here is an example of how it looks: https://c7eku786.caspio.com/dp/7f80b0006598726cb69c4239b1dc

In this forum post I would like to share 2 solutions to achieve this. One presuposses using only HTML/CSS and the second one requires JavaScript.

1. HTML/CSS solution.
1.1 Add next CSS to the header of your DataPage"

<style>
.progressbar-container {
background-color: #f1f1f1;
}
.progressbar {
background-color: #9e9e9e;
height: 24px;
padding: 5px;
color: white;  
}</style>

image.png.ea257d06dd312560239ed60bbe2d4a73.png


1.2 Add HTML block to your tabular report (results page) that will represent a progress bar
1.3 Add next HTML code to the HTML block:
 

<div class="progressbar-container">
  <div class="progressbar" style="width:[@field:ProgressBar]%;">[@field:ProgressBar]%</div>
</div>

image.png.05cc303a211688e7feedbab13b6fdf05.png
1.4 Substitute [@field:ProgressBar] with the field name where you store values from 0 to 100

2. JavaScript solution
2.1 Add the same CSS code as in 1.1
2.2 Add next JavaScript snippet to the header of your DataPage (below or above style)

<script>

if (typeof addProgressBar == 'undefined') {

const progressBarPosition = 3

const addProgressBar = ()=> {
document.querySelectorAll(`.cbResultSetTableCellNumberDate:nth-child(${progressBarPosition})`).forEach(progressBarCell => {
    let value = progressBarCell.innerText
    progressBarCell.innerHTML = `<div class="progressbar-container">
  <div class="progressbar" style="width:${value}%;">${value}%</div>
</div>`})
document.removeEventListener('DataPageReady', addProgressBar)
}

document.addEventListener('DataPageReady', addProgressBar)

}

</script>

image.png.ca3c86167ebd8d4aa266908a0cd5f945.png
2.3 Substitute value of progressBarPosition variable so it matches the position of your field that holds 0-100 value in the report DataPage

Difference between this approaches is that HTML version of the progress bar will not allow sorting once you click on the field label where JavaScript approach allows sorting once field label is clicked.

Hope this helps to someone

Link to comment
Share on other sites

  • 2 weeks later...

I was wondering if someone could help me.

I applied the solution above and got it working.

Thank You!!!!

I am having a problem with the CSS. I can manipulate the ProgressBar, but I can't manipulate the container.

image.png.a42522c3de3b86d1c50ed76dff270811.png

I have tried:

<style>
.progressbar-container {

background-color: #FFC20E;
height: 30px;
width: 75px;
}
.progressbar {
background-color: #A7DA4E;
height: 24px;
width: 75px;
color: white;  

}

I have tried auto for the height and width. 

I don't know what else to try.

Any ideas?

Lynda

Link to comment
Share on other sites

That helped. But now I have run into another problem.

The Progress Bar works as designed when the percents are within range (0 - 100)

When the percent is > 100, the ProgressBar expands past the Progress container

When the percent is < 0, the ProgressBar treats it like it is 100 percent and goes green. (see entry #3 in the example below)

I know I need some type of conditional logic, but I don't know how to modify the code. I have searched the https://www.w3schools.com website to see if they could show me how to fix this, but I have not found a solution. I am NOT a HTML/Java programmer and have limited exposure.

I really need help (in more ways than one... ;) )

The code (In the Header)

if (typeof addProgressBar == 'undefined') {

const progressBarPosition = 3

const addProgressBar = ()=> {
document.querySelectorAll(`.cbResultSetTableCellNumberDate:nth-
child(${progressBarPosition})`).forEach(progressBarCell => {
    let value = progressBarCell.innerText
    progressBarCell.innerHTML = `<div class="progressbar-container">
  <div class="progressbar" style="width:${value}%;">${value}%</div>
</div>`})
document.removeEventListener('DataPageReady', addProgressBar)
}

document.addEventListener('DataPageReady', addProgressBar)

}

The code (In an HTML block)

<div class="progressbar-container">
  <div class="progressbar" style="width:[@field:WeightLog_Progress#]%;">[@field:WeightLog_Progress#]%</div>
</div>

 

image.png.433176ede533caaea36c6f2787c264d1.png

Link to comment
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...