Skip to content

Commit 7a61cbe

Browse files
committed
grid.View: scrollByRows() #6461 WIP
1 parent 0fa7d07 commit 7a61cbe

2 files changed

Lines changed: 42 additions & 4 deletions

File tree

src/grid/View.mjs

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ class GridView extends Component {
218218
*/
219219
afterSetAvailableHeight(value, oldValue) {
220220
if (value > 0) {
221-
this.availableRows = Math.ceil(value / this.rowHeight) + 1
221+
this.availableRows = Math.ceil(value / this.rowHeight) - 1
222222
}
223223
}
224224

@@ -333,10 +333,11 @@ class GridView extends Component {
333333
if (value.y !== oldValue?.y) {
334334
newStartIndex = Math.floor(value.y / me.rowHeight);
335335

336-
if (newStartIndex < bufferRowRange) {
337-
me.startIndex = 0
338-
} else if (Math.abs(me.startIndex - newStartIndex) >= bufferRowRange) {
336+
if (Math.abs(me.startIndex - newStartIndex) >= bufferRowRange) {
339337
me.startIndex = newStartIndex
338+
} else {
339+
me.visibleRows[0] = newStartIndex;
340+
me.visibleRows[1] = newStartIndex + me.availableRows
340341
}
341342
}
342343
}
@@ -600,6 +601,8 @@ class GridView extends Component {
600601
// Creates the new start & end indexes
601602
me.updateMountedAndVisibleRows();
602603

604+
console.log('createViewData', me.startIndex, mountedRows, me.visibleRows);
605+
603606
for (i=mountedRows[0]; i < mountedRows[1]; i++) {
604607
rows.push(me.createRow({record: store.items[i], rowIndex: i}))
605608
}
@@ -851,6 +854,7 @@ class GridView extends Component {
851854
/**
852855
* Only triggers for vertical scrolling
853856
* @param {Object} data
857+
* @protected
854858
*/
855859
onScroll({scrollTop, touches}) {
856860
let me = this,
@@ -968,6 +972,38 @@ class GridView extends Component {
968972
parent.lastTouchY = 0
969973
}
970974

975+
scrollByRows(index, step) {
976+
let me = this,
977+
{mountedRows, visibleRows} = me,
978+
countRecords = me.store.getCount(),
979+
newIndex = (index + step) % countRecords,
980+
mounted, visible;
981+
982+
while (newIndex < 0) {
983+
newIndex += countRecords;
984+
step += countRecords
985+
}
986+
987+
mounted = newIndex >= mountedRows[0] && newIndex <= mountedRows[1];
988+
visible = newIndex >= visibleRows[0] && newIndex <= visibleRows[1];
989+
990+
if (!visible) {
991+
// Leaving the mounted area will re-calculate the visibleRows for us
992+
if (mounted) {
993+
visibleRows[0] += step;
994+
visibleRows[1] += step
995+
}
996+
997+
Neo.main.DomAccess.scrollBy({
998+
id : me.vdom.id,
999+
value : me.rowHeight * step,
1000+
windowId: me.windowId
1001+
})
1002+
}
1003+
1004+
console.log(visible, index, newIndex, visibleRows);
1005+
}
1006+
9711007
/**
9721008
* @param {Boolean} silent=false
9731009
*/

src/selection/grid/RowModel.mjs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ class RowModel extends BaseModel {
9494
rowId = view.getRowId(record);
9595

9696
if (rowId) {
97+
view.scrollByRows(currentIndex, step);
98+
9799
me.select(rowId);
98100
view.fire('select', {record})
99101
}

0 commit comments

Comments
 (0)