Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Updating a JQuery Tablesorter Filter Function

I am using JQuery Tablesorter, latest version, with the Filter widget applied. On two columns, I am using a filter function to display a drop-down in the filter allowing the user to select from all available values.

        widgetOptions: {
            filter_functions: {
                3: true,
                4: true
            }
        }

When the page loads, and the table is initially populated, these functions work correctly. A drop-down is created for each of my two columns, and it contains all values. Selecting a value properly filters on that value.

However, my problem comes when new rows are dynamically added to the table as the page runs. The values in the drop-down menu do not refresh, when new rows are added that contain new values. Triggering 'update', 'change', etc does not seem to work.

Is there a way to dynamically update this standard filter function when new rows are added to the table during runtime?

like image 216
Patrick D Avatar asked Nov 25 '25 17:11

Patrick D


1 Answers

Hmm, this appears to be a problem with the filter widget. I've fixed it and updated the tablesorter repository (now v2.7.2)

Here's a demo showing it working now :)

Thanks for reporting this issue!

Note: I couldn't submit this answer without any code, so this is how you should update the table:

$('table')
    .find('tbody').append(newRow)
    .trigger('update');
like image 83
Mottie Avatar answered Nov 27 '25 07:11

Mottie



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!