Table cell slow content population from API response
Hi all,
I'm noticing some odd behavior when creating a table and populating the cells' contents with a json response from an API. I've attached the video here showing how it goes cell by cell. I've tried preferences like enableRedraw in an attempt to have the table display with all the contents at once but that doesn't seem to work.
Further, I'd like to speed up this process as this isn't even a large table. Is there a more efficient way to populate a table?
async function fetchJson(url) {
return fetch(url)
.then((response) => {
return response.json();
});
}
const createTable = (textFrame, tableData) =>
{
//Get bounds of textframe to lay table on
const bounds = textFrame.geometricBounds;
columnLength = tableData.tableColumns.length;
rowLength = tableData.tableRows.length;
const table = textFrame.tables.add(
{
bodyRowCount: rowLength,
columnCount: columnLength,
width: bounds[3] - bounds[1],
});
cells = table.cells.everyItem().getElements();
tableData.tableCells.forEach(cellData => {
//calculate index in cell list based on row and column
cellIndex = cellData.rowIndex * columnLength + cellData.columnIndex;
cell = cells[cellIndex];
let texts = cell.texts.everyItem().getElements();
texts[0].contents = cellData.text;
//add labels to cell objects. These are used for formatting decisions.
cell.insertLabel("rowType" , cellData.rowType.toString());
cell.insertLabel("columnType" , cellData.columnType);
cell.insertLabel("rowIndex" , cellData.rowIndex.toString());
cell.insertLabel("columnIndex" , cellData.columnIndex.toString());
cell.insertLabel("columnAttributeId" , cellData.columnAttributeId);
cell.insertLabel("partNumbers" , cellData.partNumbers.toString());
cell.insertLabel("attributeValueIds" , cellData.attributeValueIds.toString());
cell.insertLabel("applyLeaderDots" , cellData.cellStyles.applyLeaderDots);
cell.insertLabel("bottomEdgeStrokeWeight" , cellData.cellStyles.bottomEdgeStrokeWeight);
cell.insertLabel("topEdgeStrokeWeight" , cellData.cellStyles.topEdgeStrokeWeight);
cell.insertLabel("leftEdgeStrokeWeight" , cellData.cellStyles.leftEdgeStrokeWeight);
cell.insertLabel("rightEdgeStrokeWeight" , cellData.cellStyles.rightEdgeStrokeWeight);
cell.insertLabel("verticalJustification" , cellData.cellStyles.verticalJustification);
cell.insertLabel("justification", cellData.cellStyles.justification)
cell.insertLabel("rightInset" , cellData.cellStyles.rightInset);
cell.insertLabel("leftInset" , cellData.cellStyles.leftInset);
cell.insertLabel("boldText" , cellData.cellStyles.boldText);
cell.insertLabel("font", cellData.cellStyles.font);
});
return table;
}
var resp = await fetchJson(<urlOfRespObj>);
let table = createTable(textFrame, resp[0]);

