Replace Values with Text - Pivot Table Widget
Introduction
The following enables to change the value in pivot tables to specific strings, while allowing the use of conditional coloring as normal.
Step 1 - Add The Following Script To Your Pivot's Edit Script
widget.on('ready', function(){
$('td[class*=p-value] div').map(function(i, cell) {
switch (cell.innerHTML ) {
case "10": cell.innerHTML='BAD';
break;
case "20": cell.innerHTML='OK';
break;
case "30": cell.innerHTML='MEH';
break;
default: cell.innerHTML='GOOD';
}
})
})Step 2 - Modify the values in the script according to your need
You can change the 'case' values to match the original values and the "cell.innerHTML" values to the strings you wish to present.
Note: The value after default will determine what will happen with all values not matching the cases above. If you wish to leave the original values in this case simply enter "cell.innerHTML" instead of "GOOD".
Example:
After script:
You can also achieve similar results with the following script:
fidx is the value you wish to change (starts at 1).
widget.on('ready', () => {
$('td.p-value[val="10"][fidx="1"]').text("BAD")
$('td.p-value[val="20"][fidx="1"]').text("OK")
$('td.p-value[val="30"][fidx="1"]').text("MEH")
$('td.p-value[fidx=1] div').filter(function() {return parseFloat($(this).text().replace("$","").replace(",","")) > 30;}).text("GOOD")
})By
Community_Admin
Posted 4 years ago·Last reply 1 year ago
10 comments
ssoltz
·1 year agoHi...checking back in...can anyone answer the above simple question? Does this only work in Elasticube environments or should this work in a Live Data environment?
ssoltz
·2 years agoAll,
Does this script only work in Elasticube Environments? I cannot get this to work in my Live Data environment.
Thank you!
Wojtek
·3 years agoHi Ciaran,
Not really sure, looks good to me.
I tested mine in Chrome and Edge, both works ok see below. We did another implementation of this recently and it worked fine too.
Ciaran Kirk
·3 years agoHI Wojtek,
I have tried your code on my Pivot and it doesnt seem to work.
It seems to be picking up the column name for the cell.innerHTML value and not the values themselves.
Am i missing something?
Regards,
Ciaran
Wojtek
·3 years agoHI all,
Im on L2023.2 and this works for me:
Hope this helps,
W
rvickersevotix
·3 years agoI have no idea if this will ever help anyone but I have to work with a very limited set of values and its very hard to get new stuff added in our elasticubes.
So, if you are trying to input date fields into your Pivot and dont have access to the elasticubes or the date as an integer, then this might be for you.
Firstly, you need to work out your days, I did this using ddiff:
This gave me a total number of days until required, I then used javascript to convert that days. This is where we add a script to the widget telling it to work out todays date, add the days too it, get the new date and present it back to us in a nice dd/MM/yyyy format.
You should get something that looks like this:
I also used a similar method above to change the values I was getting out:
Then in the script, I would change 111 to equal "Completed" etc
rvickersevotix
·3 years agoYeah would love to know if there is an update as neither of those work.
Wojtek
·4 years agoHi
Are those scripts still working ?
We are on L2022.4.0 . I tried both scripts and couldn't get desired result. I'm pretty sure this worked previously so I am wondering if this stopped working with last upgrade.
I would appreciate if someone could confirm, thanks.
Chris Wallingford
·4 years agoNevermind, sorted it. It's the "1" that changes (e.g. fidx="4") to indicate which column is impacted by the script.
Chris Wallingford
·4 years agoCan you expand on this in the context of your example?
> fidx is the value you wish to change (starts at 1).
Does
Become
And what is the implication of "1" here?
Thanks in advance.