wallingfordce
11-26-2025Data Pipeline
Replacing values with text: Pivot 2 script
đź‘‹ Hello,
I have clients doing this in Windows...
They might end up with a script like this:
widget.on('ready', () => {
$('td.p-value[val="1"][fidx="2"]').text("First-Time Donor")
$('td.p-value[val="0"][fidx="2"]').text("Recurring Donor")
})
widget.on('ready', function(sender, ev){
$('td[fidx=2]',element).css('text-align','left')
$('td[fidx=2]',element).css('padding-left','5px')
$('td[fidx=2]',element).css('vertical-align','middle')
});
Can you help me convert this to Pivot 2?
hey wallingfordce​ ,
Pivot table in Linux is using the Pivot 2.0 API .which has different syntax compare to the Windows Version.
The requirement is to transform Value into Text and apply Style for the target cell.Please find an example script which transform value into text and apply style. (Follow the documentation above for the Cell.Style properties)
- Targets the Indicator value/measure column
- Replaces numeric values with descriptive labels
- Applies consistent styling to the modified cells (each value can have different style)
// Specify the target value/measure column to modify const myTarget = { type: ['value'], values: [ { title: 'Indicator' // Name of the column to apply the transformation to } ] }; // Apply a transformation to each cell in the selected pivot column widget.transformPivot(myTarget, function(metadata, cell) { if (cell.value == 1) { cell.content = "First-Time Donor"; // Replace numeric value with descriptive label cell.style = { "text-align": "center", // Center text horizontally "padding-left": "5px" // Add spacing on the left side }; } else if (cell.value == 2) { cell.content = "Recurring Donor"; cell.style = { "text-align": "center", "padding-left": "5px" }; } else { cell.content = "No Donor"; cell.style = { "text-align": "center", "padding-left": "5px" }; } });Example of the Indicator_value converted to Indicator text
fyi DRay​
best regards