MCPcopy
hub / github.com/ag-grid/ag-grid / insertRow

Method insertRow

enterprise-modules/core/src/widgets/virtualList.ts:400–429  ·  view source on GitHub ↗
(rowIndex: number)

Source from the content-addressed store, hash-verified

398 }
399
400 private insertRow(rowIndex: number): void {
401 const value = this.model.getRow(rowIndex);
402 const eDiv = document.createElement('div');
403
404 eDiv.classList.add('ag-virtual-list-item', `ag-${this.cssIdentifier}-virtual-list-item`);
405 _setAriaRole(eDiv, this.ariaRole === 'tree' ? 'treeitem' : 'option');
406 _setAriaSetSize(eDiv, this.model.getRowCount());
407 _setAriaPosInSet(eDiv, rowIndex + 1);
408 eDiv.setAttribute('tabindex', '-1');
409
410 eDiv.style.height = `${this.rowHeight}px`;
411 eDiv.style.top = `${this.rowHeight * rowIndex}px`;
412
413 const rowComponent = this.componentCreator(value, eDiv);
414
415 rowComponent.addGuiEventListener('focusin', () => (this.lastFocusedRowIndex = rowIndex));
416
417 eDiv.appendChild(rowComponent.getGui());
418
419 // keep the DOM order consistent with the order of the rows
420 if (this.renderedRows.has(rowIndex - 1)) {
421 this.renderedRows.get(rowIndex - 1)!.eDiv.insertAdjacentElement('afterend', eDiv);
422 } else if (this.renderedRows.has(rowIndex + 1)) {
423 this.renderedRows.get(rowIndex + 1)!.eDiv.insertAdjacentElement('beforebegin', eDiv);
424 } else {
425 this.eContainer.appendChild(eDiv);
426 }
427
428 this.renderedRows.set(rowIndex, { rowComponent, eDiv, value });
429 }
430
431 private removeRow(rowIndex: number) {
432 const component = this.renderedRows.get(rowIndex)!;

Callers 1

ensureRowsRenderedMethod · 0.95

Calls 14

_setAriaRoleFunction · 0.90
_setAriaSetSizeFunction · 0.90
_setAriaPosInSetFunction · 0.90
componentCreatorMethod · 0.80
addGuiEventListenerMethod · 0.80
hasMethod · 0.80
setMethod · 0.80
getRowMethod · 0.65
getRowCountMethod · 0.65
getGuiMethod · 0.65
createElementMethod · 0.45
setAttributeMethod · 0.45

Tested by

no test coverage detected