Skip to content

Commit f60d3e6

Browse files
committed
Fix JavaScript TypeError: columns initialized as object instead of array
Problem: - columns was initialized as an empty object {} in grid-component-type.phtml - columns-selector-component-partial.phtml calls this.columns.forEach() - Object.forEach() is not a function, causing TypeError and page hang - Backend GridViewModel.getColumns() returns array of Column objects Solution: 1. Changed columns: {} to columns: [] in grid-component-type.phtml:20 to match expected array type from backend 2. Added Array.isArray(this.columns) safety check before forEach() in columns-selector-component-partial.phtml:15 to prevent future errors Scan Results: - Reviewed all .phtml files in the module for similar patterns - All other object/array initializations are correct for their usage - gridFilters: {} correctly used as object with bracket notation - filters: [] correctly initialized as array in filters-component-partial - No other array method calls on object-initialized properties found This fix prevents the grid component from crashing when the columns selector is initialized.
1 parent 7f44b2e commit f60d3e6

2 files changed

Lines changed: 6 additions & 4 deletions

File tree

view/adminhtml/templates/script/component-partial/columns-selector-component-partial.phtml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ use Magento\Framework\View\Element\Template;
1212
activeColumns: null,
1313
initActiveColumns() {
1414
this.activeColumns = new Set();
15-
this.columns.forEach(column => {
16-
this.activeColumns.add(column.code);
17-
})
15+
if (Array.isArray(this.columns)) {
16+
this.columns.forEach(column => {
17+
this.activeColumns.add(column.code);
18+
})
19+
}
1820
},
1921
isColumnActive() {
2022
const columnName = this.$el.getAttribute('data-column');

view/adminhtml/templates/script/component-type/grid-component-type.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use Magento\Framework\View\Element\Template;
1717
...LokiAdminFiltersComponentPartial,
1818
...LokiAdminMassActionsComponentPartial,
1919
...LokiComponentType,
20-
columns: {},
20+
columns: [],
2121
columnPositions: {},
2222
showOtherActions: false,
2323
gridFilters: {},

0 commit comments

Comments
 (0)