Reputation: 2220
I have a jquery plugin -- QuickSearch -- that I need to get to work after an ajax call so the user can still search through the table after adding/removing items from it.
Here's the code that executes the plugin:
$('.quicksearch').quicksearch('table.quicksearch>tbody>tr',{
'delay':100,
'noResults': '.quicksearch tr.noresults',
'removeDiacritics':true,
});
When I'm executing an ajax request, I empty()
the table, detach()
it, and then append()
it at the end.
After reading a bit here on SO, it looks like I have to reinitiate the plugin when the ajax call is completed - after the table(s) has been appended.
Just like I do when the page loads for the first time - as the code above.
In my case, I got it to work by putting the above code inside jqXHR.done()
.
But since I have a lot of these AJAX calls that need this plugin initiatet, I now have to add this little code at the end of each each one of them.
Is there a way to make this simpler? Or is it just how it is? It's the exact same code..
Upvotes: 0
Views: 153
Reputation: 7196
You're going to have to call that .quicksearch function on the table after you do the empty/detach/append. You can put that all in a function like resetQuicksearchTable() to make it more convenient.
You can also see if quicksearch has any sort of support for event delegation rather than attaching to the tr directly, but I've not worked with that plugin before so can't say.
Upvotes: 1