ngx-datatable icon indicating copy to clipboard operation
ngx-datatable copied to clipboard

Scroll to top does not work

Open ipassynk opened this issue 7 years ago • 12 comments

I'm submitting a ... (check one with "x")

[x ] bug report => search github for a similar issue or PR before submitting
[ ] feature request
[ ] support request => Please do not submit support request here

Current behavior Have a table with h and v scrolling. Scroll to the bottom, reload the rows and set offset to 0 to move the scroll position to the top. However, it does not affect the scroll position.

Expected behavior Move to the top when this.table.offset = 0

Reproduction of the problem https://plnkr.co/edit/iGyPA7TD46Y8BfSjVA7L

What is the motivation / use case for changing the behavior?

Please tell us about your environment:

  • Table version: 0.7.x
  • Angular version: 2.0.x
  • Browser: [all | Chrome XX | Firefox XX | IE XX | Safari XX | Mobile Chrome XX | Android X.X Web Browser | iOS XX Safari | iOS XX UIWebView | iOS XX WKWebView ]
  • Language: [all | TypeScript X.X | ES6/7 | ES5]

ipassynk avatar Apr 09 '17 01:04 ipassynk

I think I found a solution to scroll to top that works for us:

       setTimeout(() => {
         this.dataTable.offset = 0;
         this.dataTable.bodyComponent.updateOffsetY(0);
       });

ipassynk avatar Apr 16 '17 15:04 ipassynk

Would exposing this.bodyComponent.updateOffsetY(this.offset); help you?

amcdnl avatar May 05 '17 12:05 amcdnl

Was a solution ever found for this? I will need this feature if I'm to use this plugin. Thanks.

bluecaret avatar Sep 07 '17 18:09 bluecaret

@amcdnl For me this (this.bodyComponent.updateOffsetY(this.offset);) works only in chrome. For firefox it seems to cause a weird rows rendering issue - after reloading data, rows stay invisible until the table is scrolled manually. Probably because they are rendered too low (not sure)? Anyways I saw a ticket with a similar issue: https://github.com/swimlane/ngx-datatable/issues/985 I use [scrollbarV]="true", no paging. version 10.4.0 (didn't test it with v.11) Not sure if anyone else still has this problem?

szpetny avatar Nov 13 '17 08:11 szpetny

Also running into this, as a work around you can call this.table.element.getElementsByTagName('datatable-body')[0].scrollTop = 1; once you've updated the rows which causes the hidden rows to be displayed

LukeT avatar Nov 13 '17 09:11 LukeT

yea it works like that, thx

szpetny avatar Nov 13 '17 12:11 szpetny

$('datatable-body').scrollTop(0);

markanthonyg avatar Dec 13 '17 03:12 markanthonyg

I tried the updateOffsetY approach but did not work for me ... However LukeT's approach worked properly; thank you veyr much!

faridhajnal avatar May 08 '18 19:05 faridhajnal

Setting scrollTop workaround did not seem to work. When it's time to reload new data, new rows and scroll to the top, the table will report scrollTop of 0, but the rows don't render any text so you see a blank table with a scrollbar (falsely) suggesting a ton of content. Then if i move the mouse wheel or otherwise trigger a scroll event the table content actually renders, my rows, like magic, become visible. The real problem is that when the newly loaded row-set has only 1 row (or less than 1 page's worth in any case) and you can't trigger a scroll event at all - then the data never actually shows up. (tested in Chrome and FireFox)

thanks @szpetny for suggesting #985 - updateOffsetY did the trick

Balagii avatar Jun 25 '19 18:06 Balagii

Also running into this, as a work around you can call this.table.element.getElementsByTagName('datatable-body')[0].scrollTop = 1; once you've updated the rows which causes the hidden rows to be displayed

Also worked for me to scroll to certain row but it's needed to use it that way ...scrollTop = rowHeight * neededRowIndex

platon-rov avatar Nov 22 '20 13:11 platon-rov

@LukeT my scenario is like this, When i click on pagination in ngx-datatable, i have loading new data as externalPaging = true, after this i just want to scroll to top of the page, but not working, i have applying "this.gridDatatable.bodyComponent.updateOffsetY(0);" and also used perfect-scrollbar in angular Thanks in advance.

one-click-varshil-doshi avatar Apr 22 '22 08:04 one-click-varshil-doshi

I think I found a solution to scroll to top that works for us:

       setTimeout(() => {
         this.dataTable.offset = 0;
         this.dataTable.bodyComponent.updateOffsetY(0);
       });

this solution is working, tested in chrome.

sayedsadat344 avatar May 01 '23 06:05 sayedsadat344