I am experimenting with how I might be able to compare column values of two tables.
My idea is that I would like to highlight cells where a value in table2 doesn't match what is held in table1.
Both tables have matching ID columns which is what I would use to "join" on, but the name, email and sales figures in table2 might differ from table1 and I'd like to highlight those.
I know I can achieve highlighting using the "background" property of each column, and this is where I'm thinking I could write the code which does the comparison - where the column in table2 compares itself to the column with the same "id" in table1.
for (i=0;i<table4.data.length;i++){
if (table4.data[i].Amount != table1.data[i].Amount)
table4.data[i].Amount.backgroundColor = '#FFFFE0'
console.log(table4.data[i].Amount + ' table 4');
console.log(table1.data[i].Amount + ' table 1');
}
which gives me:
So, it picks up the difference in the Amount in the two tables, but it is NOT setting the color... so I am still working on what property needs to be used.....backgroundColor is not working....
Thanks Scott, that seems like a good starting point!
Excuse my ignorance here as I've not had to insert custom JS into the IDE before, could you advise on how that is done?
At the moment you can only set properties on components if they have specific methods allowing you to do so (check out this post for more detail).
Since you're trying to dynamically set the background you can use an inline transformer in the "Background" field to determine the color. How you actually write the JS can vary but here is one example that uses the self and i variables which are dynamically interpolated based on the cell - self represents the value of the cell and i represents the row index:
This checks to see if the value in the cell is equal to the value of the name column in the corresponding row of table1.
**Note** the exact syntax can vary here a bit depending on the structure of your table data. This example assumes your data is an array of row objects, however, if your data is an object of column arrays, as with SQL queries, you might want something like {{ self !== table1.data.name[i] ? '#ffaaaa' : 'white' }} or {{ self !== formatDataAsArray(table1.data)[i].name ? "#ffaaaa" : "white" }} instead.
@Kabirdas , @ScottR - this looks like a winner... sorry to be a pain but i'm struggling with the transformer element of this so can you advise on what you did there? I guess I need to set something up which returns 'i' but not quite got my head around that!