sorttable.js with (ajax)will_paginate

Hi,

I'm trying to integrate a sorting method with will_paginate. I like the
sorttable.js for its simplicity but when I tried to integrate it with my
ajax paginated lists it just works for the first page, others pages just
can't be sorted.

If I use the regular pagination, it works for all pages.

Have anyone had the same problem? If someone could suggest other sorting
script/plugin/gem that would work with an ajax will_paginate version, it
would be great.

Thanks!

Hi,

I'm trying to integrate a sorting method with will_paginate. I like the
sorttable.js for its simplicity but when I tried to integrate it with my
ajax paginated lists it just works for the first page, others pages just
can't be sorted.

If I use the regular pagination, it works for all pages.

Have anyone had the same problem? If someone could suggest other sorting
script/plugin/gem that would work with an ajax will_paginate version, it
would be great.

I haven't tried to do this, but from what you're describing, it sounds like the ajax pagination is replacing the elements that you intend to sort. Sortable.create runs once to instantiate the sortable behavior on an element and its children. Try moving the sortable call up a level into the same partial you replace with your pagination call:

outer page
  pagination controls/
  paginated element
    N x listed elements
    (move your call to Sortable.create here)
  /paginated element
  pagination controls/
  (it sounds like it's currently located here)
/outer page

A call to Sortable.create on an element implicitly removes any existing Sortable behavior from it. Removing or updating the children from within an already-running sortable does not run that setup function again, so you have to force it to run again.

Walter