jquery-fastLiveFilter icon indicating copy to clipboard operation
jquery-fastLiveFilter copied to clipboard

How to reinitialise plugin if DOM changes?

Open christophermiles opened this issue 10 years ago • 4 comments

I note from the source code that the variables lis and len are cached, and the comments in the code suggest reinitialising the plugin if the DOM changes after the plugin is first initialised.

Is there a fork of this code which doesn't cache those variables?

Alternatively, how can I reinitialise the plugin if the DOM changes subsequent to the plugin initialising?

christophermiles avatar May 25 '15 23:05 christophermiles

Did you ever find a solution to this? I have the same issue. Tabs update the content via ajax, once that has happened the filter no longer works

craigivemy avatar Aug 20 '15 20:08 craigivemy

I have the same issue. Do you know how to solve it? Thanks

jrioromero avatar Sep 21 '15 11:09 jrioromero

Put your initial filter init code in a function. Run this function whenever you need it. E.g. I have an image gallery of 4000 images. If I delete 2500 images at once, or add another 3000, the function is ran in my delete callback.

Also using jQuery UI draggable, I run the function when an element s dropped in another div.

function runMyAwesomeFilter() {
        // Activate fastLiveFilter w/ callback
        var numDisplayed = $(".num_displayed");
        $("#filter_input").fastLiveFilter("#list_to_filter", {
            callback: function (total) {
                numDisplayed.html(addCommas(total));
                //do more stuff
                //do more stuff
                //do more stuff
            },
        });
    }

call this whenever you need it runMyAwesomeFilter(); at startup, after DOM change, etc.

donShakespeare avatar Oct 09 '15 06:10 donShakespeare

@donShakespeare i think the problem in your solution is that all elements are cached each time you call that function. So if you call that function multiple times the overall javascript performance will drop depending on how many elements there are and how often the function was called …

ghost avatar May 30 '18 07:05 ghost