cancel
Showing results for 
Search instead for 
Did you mean: 

How to apply javascript to all pages of a table

jfarmer
7 - Data Storage
7 - Data Storage

I have the following script that modifies the values within a couple columns in this table widget and it works just fine. The issue I am having is it only applies to the first page of the table, and as soon as I change the page the changes are no longer applied. Is there an event associated with changing pages of a table I can set up in the script to make sure it runs when pages are changed? 

Thanks in advance. 

 

 

widget.on('domready', function(se, ev) {
		
	var tableObject = document.getElementById("grid");
	for (var r = 1, n = tableObject.rows.length; r < n; r++) {
		if (tableObject.rows[r].cells[5].innerHTML == 1){
			tableObject.rows[r].cells[5].innerHTML = "True";
		}
		else{
			tableObject.rows[r].cells[5].innerHTML = "False";
		};
		if (tableObject.rows[r].cells[6].innerHTML == 1){
			tableObject.rows[r].cells[6].innerHTML = "True";
		}
		else{
			tableObject.rows[r].cells[6].innerHTML = "False";
		}
	};
});

 

 

 

3 REPLIES 3

KatieG
Sisense Team Member
Sisense Team Member

Hi @jfarmer - is your Sisense instance running on Windows or Linux? If you're unsure, please refer to this article on how to check: Check whether running Sisense on Linux or Windows

Based on that info, we can give you more specifics.

Thanks,

Katie G | Sisense Pre-Sales Solutions Architect

jfarmer
7 - Data Storage
7 - Data Storage

It is running on Linux, Sisense hosted. Also this is a table widget type object, not a pivot2 object if that helps. 

KatieG
Sisense Team Member
Sisense Team Member

Hi @jfarmer , spent some time testing and I did not find a script solution that worked super well. 

Some of the limitations to a script solution I found:

  • Going from a numeric data type to a string data type in a table widget (value 1 to "True") did not seem to work - only worked if the data type was the same (numeric to numeric)
  • The native widget event to put the logic behind ("processcell") does not fire for every page of results - just the first 10 or so pages

The script that somewhat worked (but again has the limits above, I don't recommend using it as is)

// list of column names to apply logic to
let columnTitleList = ['Column5', 'Column6']

widget.on('processcell', function(ev, widget){
//console.log(widget)
if(columnTitleList.includes(widget.item.jaql.title)){
if(widget.cell.data === 1){
widget.cell.data = 50000
//console.log(widget.cell.text)
}
else {
widget.cell.data = 60000
}
}
})

I think we can get the result you are looking for via a different method:

______________________________________________________________

If this is a regular table:

I recommend you add a custom column in the Elasticube model that contains the True or False logic and use those columns in the table widget as is - 

KatieG_5-1652191983569.png

KatieG_2-1652191639878.png

Before model changes:

KatieG_3-1652191826958.png

After model changes:

KatieG_4-1652191857950.png

If this is a table with aggregation:

Unless there is a specific reason to use the table w/agg, switch the type to pivot table. Then you can use this script below (uses newer Pivot 2 API):

// List Value names
let colList = ["Value4", "Value5"]

widget.transformPivot(
{
type: ['value']
},
function (metadata, cell) {
if(colList.includes(metadata.measure.title)){
if(cell.value === "1"){
cell.content= "True"
}
else {
cell.content= "False"
}
}
}
);

Before script:

KatieG_0-1652191420878.png

After script:

KatieG_1-1652191473500.png

Hope that helps!

Katie G | Sisense Pre-Sales Solutions Architect
Voice of Customer
Impact Business Intelligence (BI) and Analytics Market Research

Click Here & Complete Dresner's Wisdom of Crowds® Market Study Survey Today!

Community Toolbox

Recommended quick links to assist you in optimizing your community experience:

Need additional support?:

Community Support Request

Don't miss out:

Earn a BETA Launch Challenge Badge!