Falko
Falko

Reputation: 1038

PrimeFaces dataTable - how to scroll to its bottom on change

I have a PrimeFaces dataTable that gets refreshed on actions of various controls of the page. (I use p:ajax update="myDataTable" ..)

I have a JavaScript method calling row.scrollIntoView(true) on the last table row. (The nicer row.scrollIntoViewIfNeeded(true) seems to be available only in Chrome.)

Well, I need the table to scroll to the last entry on such a refresh. Is there any event I can listen to? Or is there an alternative way?

Upvotes: 1

Views: 6016

Answers (2)

Exterminator13
Exterminator13

Reputation: 2182

Use JQuery for (it's supported by PrimeFaces natively):

function scrollToBottom() {
    $('.ui-datatable-scrollable-body').scrollTop(100000)
}

Next,

<p:ajax update="myDataTable" oncomplete="scrollToBottom()"/>

Upvotes: 2

Matt Handy
Matt Handy

Reputation: 30025

The p:ajax tag has an oncomplete attribute. You could use:

<p:ajax update="myDataTable" oncomplete="yourJsMethod()"/>

Upvotes: 1

Related Questions