I am loading a dynamic table from a JSON file and on td i am using an angular expression to evaluate the css class name based on some application logics The HTML and TS code is like below
<td *ngFor='let colData of rowData.columns'
id="{{colData.colIndex}}"
(click)="selectColumn(colData.colIndex)"
[ngClass]="getColumnClassName(colData.colIndex,rowData.rowIndex)"
name="cell">
{{colData.cell.value}}
</td>
getColumnClassName(selectedColIndex,selectedRowIndex):string {
var colSelected = 'cell-default';
if (this.selectionSettings.columnsToSelect.filter(e => e.colIndex === selectedColIndex).length > 0) {
if (selectedRowIndex >= this.selectionSettings.startIndex ) {
colSelected = 'cell-selected'
}
}
return colSelected;
}
This is working correctly.
Sometimes the JSON might contain so many records [ 1000 rows and 10 columns ] So this CSS expression will be evaluated 1000*10 times . Also chances that this list might increase
Does this approach of assign CSS classes is optimal when it comes to performance . I am feeling the UI is getting frozen at times of rendering tables with so many records How can we ensure the browser is not overloaded , but correctly assign CSS classes?