Skip to content

Commit e30372e

Browse files
committed
Neo.main.DomAccess: scrollToTableRow #324
1 parent 76a6e7c commit e30372e

2 files changed

Lines changed: 28 additions & 1 deletion

File tree

apps/covid/view/MainContainerController.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ class MainContainerController extends ComponentController {
260260
id = selectionModel.getRowId(activeView.store.indexOf(value.country));
261261
selectionModel.select(id);
262262

263-
Neo.main.DomAccess.scrollIntoView({id: id});
263+
Neo.main.DomAccess.scrollToTableRow({id: id});
264264
} else if (activeView.ntype === 'helix') {
265265
selectionModel.select(value.country, false);
266266
} else {

src/main/DomAccess.mjs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ class DomAccess extends Base {
5555
'getBoundingClientRect',
5656
'markdownToHtml',
5757
'scrollIntoView',
58+
'scrollToTableRow',
5859
'selectNode',
5960
'swapStyleSheet',
6061
'windowScrollTo'
@@ -358,6 +359,32 @@ class DomAccess extends Base {
358359
return {id: data.id};
359360
}
360361

362+
/**
363+
*
364+
* @param {Object} data
365+
* @param {String} data.id
366+
* @param {String} [data.behavior='smooth']
367+
* @param {String} [data.offset=34]
368+
* @returns {Object} obj.id => the passed id
369+
*/
370+
scrollToTableRow(data) {
371+
let node = this.getElement(data.id); // tr tag
372+
373+
if (node) {
374+
let tableNode = node.parentNode.parentNode,
375+
wrapperNode = tableNode.parentNode,
376+
tableTop = tableNode.getBoundingClientRect().top,
377+
top = node.getBoundingClientRect().top;
378+
379+
wrapperNode.scrollTo({
380+
top : top - tableTop - (data.hasOwnProperty('offset') ? data.offset : 34),
381+
behavior: data.behavior || 'smooth'
382+
});
383+
}
384+
385+
return {id: data.id};
386+
}
387+
361388
/**
362389
*
363390
* @param {Object} data

0 commit comments

Comments
 (0)