Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions cypress/e2e/example-0032-row-span-many-columns.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,37 @@ describe('Example - colspan & rowspan spanning many columns', { retries: 0 }, ()
.each(($child, index) => expect($child.text()).to.eq(fullTitles[index]));
});

it('keeps spanning cells above active and hovered covered rows', () => {
const expectSpanAtRow = (selector: string, rowIndex: number) => {
cy.get(selector).should(($span) => {
const span = $span[0];
const row = span.ownerDocument.querySelector<HTMLElement>(`#myGrid .slick-row[data-row="${rowIndex}"]`)!;
const spanRect = span.getBoundingClientRect();
const rowRect = row.getBoundingClientRect();
const painted = span.ownerDocument.elementFromPoint(spanRect.left + spanRect.width / 2, rowRect.top + rowRect.height / 2);
expect(painted === span || span.contains(painted)).to.eq(true);
});
};

cy.get('#myGrid .slick-row[data-row="3"] > .slick-cell.l2').click();
expectSpanAtRow('#myGrid .slick-row[data-row="2"] > .slick-cell.l0.rowspan', 3);
cy.get('#myGrid .slick-row[data-row="4"] > .slick-cell.l2').realHover();
expectSpanAtRow('#myGrid .slick-row[data-row="2"] > .slick-cell.l0.rowspan', 4);
expectSpanAtRow('#myGrid .slick-row[data-row="3"] > .slick-cell.l3.rowspan', 4);
cy.get('h2').realHover();
});

it('retains the tall rowspan host while scrolling vertically', () => {
let host: HTMLElement;
cy.get('#myGrid .slick-row[data-row="8"]').then(($row) => { host = $row[0]; });
cy.get('#myGrid .slick-viewport-top.slick-viewport-left').scrollTo(0, 900);
cy.get('#myGrid .slick-row[data-row="8"]').should(($row) => {
expect($row[0]).to.equal(host);
expect($row.find('.slick-cell.l3.rowspan')).to.have.length(1);
});
cy.get('#myGrid .slick-viewport-top.slick-viewport-left').scrollTo(0, 0);
});

it('should clamp an off-screen resize to the viewport and continue widening at 10px per 30ms', () => {
let widthAtViewportEdge = 0;
const headerSelector = '#myGrid .slick-header-columns .slick-header-column:first-child';
Expand Down
34 changes: 31 additions & 3 deletions src/__tests__/slickGrid.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,34 @@ describe('SlickGrid core file', () => {
expect(grid.getCellFromEvent({ target: spanCell } as unknown as Event)).toEqual({ row: 0, cell: 1 });
});

it('retains an offscreen span host and renders its newly visible columns', () => {
const dataView = new SlickDataView({
globalItemMetadataProvider: { getRowMetadata: (_item, row) => (row === 0 ? { columns: { 0: { rowspan: 3 }, 1: { rowspan: 3 } } } : undefined) },
});
dataView.setItems([{ id: 0 }, { id: 1 }, { id: 2 }]);
grid = new SlickGrid<any, Column>(container, dataView, [
{ id: 'id', field: 'id', width: 100 },
{ id: 'other', field: 'id', width: 100 },
], { ...defaultOptions, enableCellRowSpan: true });
grid.init();
const internalGrid = grid as any;
const range = { top: 1, bottom: 1, leftPx: 0, rightPx: 50 };
internalGrid.removeRowFromCache(0);
internalGrid.removeRowFromCache(1);
internalGrid.renderRows(range);
const host = container.querySelector('.slick-row[data-row="0"]');
expect(host?.querySelector('.slick-cell.rowspan')).toBeTruthy();
expect(host?.querySelector('.slick-cell.l1')).toBeNull();

internalGrid.cleanUpAndRenderCells({ ...range, leftPx: 100, rightPx: 200 });
expect(host?.querySelector('.slick-cell.l1.rowspan')).toBeTruthy();

internalGrid.removeRowFromCache(1);
internalGrid.scrollLeft = internalGrid.lastRenderedScrollLeft + 10;
internalGrid.renderRows(range);
expect(container.querySelector('.slick-row[data-row="0"]')).toBe(host);
});

it('should be able to instantiate SlickGrid and get columns', () => {
const columns = [
{ id: 'firstName', field: 'firstName', name: 'First Name', headerCssClass: 'header-class', headerCellAttrs: { 'some-attr': 3 } },
Expand Down Expand Up @@ -2722,8 +2750,8 @@ describe('SlickGrid core file', () => {

expect(remapRowspanSpy).toHaveBeenCalled();
expect(slickCell0).toBeTruthy();
expect(slickCells.length).toBe(48);
expect(getDataSpy).toHaveBeenCalledTimes(32);
expect(slickCells.length).toBe(54);
expect(getDataSpy).toHaveBeenCalledTimes(31);
});

describe('getViewportHeight() method', () => {
Expand Down Expand Up @@ -2942,7 +2970,7 @@ describe('SlickGrid core file', () => {
grid.setActiveCell(0, 0);
grid.editActiveCell(InputEditor as any, true);
expect(container.querySelector('.editor-text')?.getAttribute('aria-label')).toBe('Name & title');
grid.getEditController().cancelCurrentEdit();
grid.getEditController()?.cancelCurrentEdit();
editorColumns[0].editorAriaLabel = 'Custom editor';
grid.editActiveCell(InputEditor as any, true);
expect(container.querySelector('.editor-text')?.getAttribute('aria-label')).toBe('Custom editor');
Expand Down
14 changes: 12 additions & 2 deletions src/slick.grid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6604,7 +6604,15 @@ export class SlickGrid<TData = any, C extends Column<TData> = Column<TData>, O e
}
}

for (const row of rowsToProcess) {
// Span hosts above the render range still need horizontally virtualized cells.
const rowsToProcessSet = new Set(rowsToProcess);
for (const row of Object.keys(this.rowsCache).map(Number)) {
if (this.rowsCache[row].rowSpanHost) {
rowsToProcessSet.add(row);
}
}

for (const row of rowsToProcessSet) {
cacheEntry = this.rowsCache[row];
if (cacheEntry) {
// cellRenderQueue populated in renderRows() needs to be cleared first
Expand Down Expand Up @@ -6763,7 +6771,9 @@ export class SlickGrid<TData = any, C extends Column<TData> = Column<TData>, O e
const mandatorySpanRows = this.setDifference(renderingRows, mustRenderRows);
if (mandatorySpanRows.size > 0) {
mandatorySpanRows.forEach((r) => {
this.removeRowFromCache(r); // remove any previous element to avoid duplicates in DOM
if (this.rowsCache[r]) {
return;
}
rows.push(r);
this.rowsCache[r] = this.createEmptyCachingRow();
this.appendRowHtml(divArray, r, range, dataLength);
Expand Down
Loading