Skip to content

Commit

Permalink
chore: fix a small regression with navigateTop/Bottom
Browse files Browse the repository at this point in the history
  • Loading branch information
ghiscoding committed Jan 18, 2025
1 parent 7da1441 commit 0c631f7
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 28 deletions.
8 changes: 8 additions & 0 deletions cypress/e2e/example4-model-esm.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,12 @@ describe('Example 4 - Model (ESM)', () => {
cy.get(`[style*="top: ${GRID_ROW_HEIGHT * 18}px;"] > .slick-cell:nth(2)`).should('contain', '5 days').click();
cy.get('.editor-text').should('not.exist');
});

it('should navigate to bottom/top of the grid with command execution', () => {
cy.get('[data-test="navigate-bottom"]').click();
cy.get('[data-row=49999]').should('contain', 'Task 49999');

cy.get('[data-test="navigate-top"]').click();
cy.get('[data-row=1]').should('contain', 'Task 1');
});
});
8 changes: 8 additions & 0 deletions cypress/e2e/example4-model.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ describe('Example 4 - Model', () => {
});
});

it('should navigate to bottom/top of the grid with command execution', () => {
cy.get('[data-test="navigate-bottom"]').click();
cy.get('[data-row=49999]').should('contain', 'Task 49999');

cy.get('[data-test="navigate-top"]').click();
cy.get('[data-row=1]').should('contain', 'Task 1');
});

it('Should display "Showing page 1 of 1000" text after changing Pagination to 50 items per page', () => {
cy.get('.sgi-lightbulb')
.click();
Expand Down
22 changes: 0 additions & 22 deletions examples/example-0031-row-span-employees.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,6 @@
<link rel="stylesheet" href="../dist/styles/css/slick-alpine-theme.css" type="text/css"/>
<link rel="stylesheet" href="../dist/styles/css/slick-icons.css" type="text/css"/>
<style>
button.btn {
background-color: white;
border: 1px solid #9a9a9a;
border-radius: 3px;
display: inline-flex;
align-items: center;
justify-content: center;
padding: 6px 8px;
gap: 4px;
}
.rotate-90 {
transform: rotate(90deg);
}
.rotate-180 {
transform: rotate(180deg);
}
.rotate-270 {
transform: rotate(270deg);
}
.text-italic {
font-style: italic;
}
#myGrid {
--alpine-odd-row-color: #fff;
--alpine-cell-border-width: 0 1px 1px 0;
Expand Down
17 changes: 16 additions & 1 deletion examples/example4-model-esm.html
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,15 @@ <h2>
<label style="width:200px;float:left">And title including:</label>
<input type=text id="txtSearch" style="width:100px;">
<br/><br/>
<button id="btnSelectRows">Select first 10 rows</button>
<div style="display: flex; gap: 4px;">
<button class="btn" id="btnSelectRows">Select first 10 rows</button>
<button class="btn" id="btnNavigateBottom" data-test="navigate-bottom" title="Navigate Down Cell">
<span class="sgi sgi-chevron-left rotate-270"> </span>
</button>
<button class="btn" id="btnNavigateTop" data-test="navigate-top" title="Navigate Up Cell">
<span class="sgi sgi-chevron-left rotate-90"> </span>
</button>
</div>

<br/>

Expand Down Expand Up @@ -379,6 +387,13 @@ <h2>View Source:</h2>
dataView.refresh();
}

document.querySelector("#btnNavigateBottom").addEventListener('click', () => {
grid.navigateBottom();
});
document.querySelector("#btnNavigateTop").addEventListener('click', () => {
grid.navigateTop();
});

document.querySelector("#btnSelectRows").addEventListener('click', () => {
if (!SlickGlobalEditorLock.commitCurrentEdit()) {
return;
Expand Down
10 changes: 9 additions & 1 deletion examples/example4-model.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,15 @@ <h2>
<label style="width:200px;float:left">And title including:</label>
<input type=text id="txtSearch" style="width:100px;">
<br/><br/>
<button id="btnSelectRows">Select first 10 rows</button>
<div style="display: flex; gap: 4px;">
<button class="btn" id="btnSelectRows">Select first 10 rows</button>
<button class="btn" id="btnNavigateBottom" data-test="navigate-bottom" title="Navigate Down Cell" onclick="grid.navigateBottom()">
<span class="sgi sgi-chevron-left rotate-270"> </span>
</button>
<button class="btn" id="btnNavigateTop" data-test="navigate-top" title="Navigate Up Cell" onclick="grid.navigateTop()">
<span class="sgi sgi-chevron-left rotate-90"> </span>
</button>
</div>

<br/>

Expand Down
12 changes: 8 additions & 4 deletions src/slick.grid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6675,8 +6675,11 @@ export class SlickGrid<TData = any, C extends Column<TData> = Column<TData>, O e
let tmpRow = this.getParentRowSpanByCell(row, this.activeCell)?.start ?? row;

do {
this.setActiveRow(tmpRow);
if (this.navigateToRow(tmpRow) && this.activeCell === this.activePosX) {
if (this._options.enableCellRowSpan) {
this.setActiveRow(tmpRow);
}
const isValidMode = this.navigateToRow(tmpRow);
if ((isValidMode && this.activeCell === this.activePosX) || !Utils.isDefined(this.activeCell)) {
break;
}
} while (--tmpRow > 0);
Expand All @@ -6693,15 +6696,16 @@ export class SlickGrid<TData = any, C extends Column<TData> = Column<TData>, O e
}

this.scrollCellIntoView(row, 0, true);
let isValidMove = false;
let isValidMove = !Utils.isDefined(this.activeCell) || !Utils.isDefined(this.activeRow);

if (this._options.enableCellNavigation && Utils.isDefined(this.activeRow)) {
let cell = 0;
let prevCell: number | null = null;
const prevActivePosX = this.activePosX;
while (cell <= this.activePosX) {
if (this.canCellBeActive(row, cell)) {
prevCell = cell;
if (cell === this.activeCell) {
if (!Utils.isDefined(this.activeCell) || cell === this.activeCell) {
isValidMove = true;
}
}
Expand Down
24 changes: 24 additions & 0 deletions src/styles/example-demo.scss
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,28 @@ ul {
font-family: var(--alpine-font-family, $alpine-font-family);
font-size: 12px;
}
}

button.btn {
cursor: pointer;
background-color: white;
border: 1px solid #9a9a9a;
border-radius: 3px;
display: inline-flex;
align-items: center;
justify-content: center;
padding: 6px 8px;
gap: 4px;
}
.rotate-90 {
transform: rotate(90deg);
}
.rotate-180 {
transform: rotate(180deg);
}
.rotate-270 {
transform: rotate(270deg);
}
.text-italic {
font-style: italic;
}

0 comments on commit 0c631f7

Please sign in to comment.