Skip to content

Commit

Permalink
Pass through 'idForFirstItem' to the vertical-collection, so scroll-p…
Browse files Browse the repository at this point in the history
…osition can be restored (#616)

* CHG: now 'idForFirstItem' is passed through to the vertica-collection, so there's a possibility to restore scroll-position

* CHG: add idForFirstItem-test
  • Loading branch information
wuarmin authored and twokul committed Nov 12, 2018
1 parent 7d6d54f commit 9be6870
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
10 changes: 10 additions & 0 deletions addon/components/ember-tbody/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,16 @@ export default class EmberTBody extends Component {
@type('string')
key = '@identity';

/**
The property is passed through to the vertical-collection. If set, upon initialization
the scroll position will be set such that the item
with the provided id is at the top left on screen.
If the item with id cannot be found, scrollTop is set to 0.
*/
@argument({ defaultIfUndefined: true })
@type(optional('string'))
idForFirstItem = null;

/**
A selector string that will select the element from
which to calculate the viewable height.
Expand Down
1 change: 1 addition & 0 deletions addon/components/ember-tbody/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
lastReached=lastReached
firstVisibleChanged=firstVisibleChanged
lastVisibleChanged=lastVisibleChanged
idForFirstItem=idForFirstItem

as |rowValue|
}}
Expand Down
4 changes: 4 additions & 0 deletions tests/helpers/generate-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ const fullTable = hbs`
staticHeight=staticHeight
enableCollapse=enableCollapse
enableTree=enableTree
key=key
bufferSize=bufferSize
idForFirstItem=idForFirstItem
onSelect="onSelect"
selectingChildrenSelectsParent=selectingChildrenSelectsParent
Expand Down
21 changes: 21 additions & 0 deletions tests/integration/components/basic-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,27 @@ module('Integration | basic', function() {
);
});

test('idForFirstItem works, so scroll position can be restored', async function(assert) {
let rowCount = 100;
let columnCount = 10;

await generateTable(this, {
columnCount,
rowCount,
key: 'id',
idForFirstItem: '60',
bufferSize: 0,
});

assert.ok(table.rows.length < rowCount, 'not all rows have been rendered');
assert.equal(table.getCell(0, 0).text.trim(), '60A', 'correct first row rendered');
assert.notEqual(
table.getCell(table.rows.length - 1, 0).text.trim(),
'99A',
'last rendered row is not last data row'
);
});

test('fixed cells work', async function(assert) {
function validateElements(container, elements, measurement) {
for (let element of elements) {
Expand Down

0 comments on commit 9be6870

Please sign in to comment.