I have a partial that initial displays a table of active workflows. There is a link_to in the partial that rerenders it with all workflows, to allow people to see them all if they wish.
All works fine, except I’m using tablesorter and jQuery and when I rerender the partial, I lose the table sorting and some of the jQuery styles. I think it’s because some classes on some HTML elements go missing.
I guess it’s because things get initialized on document ready in application.js and those calls are not made on the AJAX rerender.
What I’m not sure of is how to fix it . . . ?
You need to call the initialisation code again at the end of your Ajax request. Like you said, the jQuery behaviour is applied in the ready event, so it won’t apply to DOM elements created after that.
As an aside, jQuery has
.livefunction to mitigate this issue for event handlers. It applies the handler to any element that matches the selector regardless of when it was created.