koalyptus / TableFilter

A Javascript library making HTML tables filterable and a bit more :)
https://www.tablefilter.com
MIT License
323 stars 95 forks source link

A callback that triggers after changes made to a filter and after the paginator is applied #778

Closed M-Mommsen closed 4 years ago

M-Mommsen commented 4 years ago

When lazy loading of images is needed, there are no triggers to check which rows are currently visible after changing a filter! I am using a jquery filter like: tr[validrow="true"] img.lazy_load:visible But since the on_after_filter callback is triggered before applying the paginator, it would return all rows - of all pages!

Needed: Either fire on_before_change_page and on_after_change_page, or add a new callback like on_refreshed/on_change_visibility when a filter is changed and the paginator is applied! Or on_after_filter should be triggered later. Or another way to supply a function with a list of all actually visible rows

koalyptus commented 4 years ago

Hi @M-Mommsen , please be aware of the following rows visibility APIs:

All the above support a paginated table, there shouldn't be any need for additional callbacks or events.

Cheers

M-Mommsen commented 4 years ago

Hi @M-Mommsen , please be aware of the following rows visibility APIs:

All the above support a paginated table, there shouldn't be any need for additional callbacks or events.

Cheers

Sorry, but after applying a filter, there are some "on_row_validated" events and one "on_after_filter" event. But in all the events with getVisibleColumnData(), I do NOT not get only the items visible on the page, but all items within the filter!

M-Mommsen commented 4 years ago

My workaround for now: Lazy loading checks start only after I receive a on_after_change_page event first. I start a timer of 1 second in on_after_filter, and then, I use getVisibleColumnData(). Furthermore I catch some more events like emitter->after-page-length-change

I don't know if there is an easier way, but at least, for now I am okay with this... it's just not pretty at all!

koalyptus commented 4 years ago

@M-Mommsen , right I see what you mean! This example should kill your timer and simplify your workaround. When paging is on, that's the event you are looking for: grouped-by-page : https://codepen.io/koalyptus/pen/ZEboajz

Cheers

M-Mommsen commented 4 years ago

@M-Mommsen , right I see what you mean! This example should kill your timer and simplify your workaround. When paging is on, that's the event you are looking for: grouped-by-page : https://codepen.io/koalyptus/pen/ZEboajz

Cheers

Thanks it seems 'grouped-by-page' and 'on_after_change_page' callback give a working combination! This way on paging it's called twice, but that is okay for me!

koalyptus commented 4 years ago

You probably dont need on_after_change_page, grouped-by-page event as per above demo covers also page changes and column sorting.

M-Mommsen commented 4 years ago

You probably dont need on_after_change_page, grouped-by-page event as per above demo covers also page changes and column sorting.

The first "grouped-by-page event" did not contain any visible rows in my tests! So I needed some initial event.

koalyptus commented 4 years ago

The demo above does not need any 'initial event' and displays the visible column data at start-up.