About Tabulator Widget

Hello friends, I would like to know if it is possible to launch an event when clicking on the next button of the Tabulator’s pagination
Example: if you click next, launch an event besides changing page
image
I would like it, when clicking the next button on the last page, to call a method

1 Like

I had to add an intermediate widget to track page. Couldn’t figure out how to watch Tabulator.page directly:

import panel as pn
import pandas as pd
# pn.extension('tabulator')
large_df = pd._testing.makeCustomDataframe(100000, 5)
big = pn.widgets.Tabulator(large_df, pagination='remote', page_size=3)
pg_tracker = pn.widgets.IntInput(value=big.page)
link = pg_tracker.jslink(big, value='page', bidirectional = True)
@pn.depends(a=pg_tracker)
def add(a):
    return 'You are on page ' + str(a)
pn.Column(big, pg_tracker, add)
2 Likes

Oooh, this works without the intermediate widget:

import panel as pn
import pandas as pd
# pn.extension('tabulator')
large_df = pd._testing.makeCustomDataframe(100000, 5)
big = pn.widgets.Tabulator(large_df, pagination='remote', page_size=3)
md = pn.pane.Markdown('')
def callback(target, event):
    target.object = str('# PAGE ' + str(event.new) + '!')
link = big.link(md, callbacks={'page': callback})
pn.Column(big, md)
1 Like

You can’t watch when someone clicks on Next. What you can do however is watch the page Parameter, and in this case using .param.watch you can get a hold on the old value (which you can’t do with the easier to use @param.depends or @pn.depends):

def callback(event):
    if event.new - event.old == 1:
        print('next page')

tabulator_obj.param.watch(callback, 'page')

Good point. My callback triggers on any page change, not just “next”.