Copy link to clipboard
Copied
Hi all, I have a question regarding getElements() and it's behavior. I've found that when I apply styles to the returned collection from getElements() the styles do not update on the UI. However, when I apply styles to the returned collection from everyItem() it correctly updates the UI.
I read this post explaining that getElements() returns a static array which limits the interaction with InDesign to improve performance. https://community.adobe.com/t5/indesign-discussions/quot-everyitem-getelements-quot-what-use/m-p/880...
Here's my issue: I would like to selectively apply styles to cells. EveryItem() does not support js lambda expressions like .filter() so my only option is to use getElements(). Is there a way to force an interaction between the returned array from getElements() and InDesign so the style is reflected properly?
Style updated/rendered correctly:
var myCells = table.cells.everyItem();
myCells.appliedCellStyle = stylez;
Style not updated/rendered correctly:
var myCells = table.cells.everyItem().getElements().filter(cell => cell.extractLabel("rowType") === "0");
myCells.appliedCellStyle = stylez;
Copy link to clipboard
Copied
Hi @Phil 815,
Instead of
var myCells = table.cells.everyItem().getElements().filter
(
cell => cell.extractLabel("rowType") === "0"
);
// Cannot work since Array doesn't support `appliedCellStyle`!
myCells.appliedCellStyle = stylez;
it looks like you simply need forEach:
table.cells.everyItem().getElements().forEach
(
c => c.extractLabel("rowType")==="0" && (c.appliedCellStyle=stylez)
);
Note: I assumed you're programming in UXP syntax (idjs). In ExtendScript, just loop in myCells (unfiltered) and do the same:
// ExtendScript version
// . . .
var myCells = table.cells.everyItem().getElements();
var c,i;
for
( i=myCells.length ; i-- ;
(c=myCells[i]).extractLabel("rowType")==="0" && (c.appliedCellStyle=stylez)
);
Best,
Marc
Find more inspiration, events, and resources on the new Adobe Community
Explore Now