Imtiaz Mirza
Imtiaz Mirza

Reputation: 591

Ajax repainting component stops loading Javascripts

I have a wicket form - when I click submit - its shows me the dynamic table from the database - I want the table to be sortable - so I used listview repeater and table sorttable.js to able to sort the table.

Now when I refreash the page - I have the sorting capability available - but when I click submit - I can't sort the table

       wmc.add(new AttributeAppender("class", new Model("sorttable"), ";"));
       wmc.add(new AttributeAppender("onclick", new Model("sorttable()"), ";"));

       <table class="sortable" wicket:id="someContainer">

Is there any way - where I can reload my sorttable.js - while ajax repaint is done ?

Upvotes: 1

Views: 192

Answers (3)

osdamv
osdamv

Reputation: 3583

when you insert some javascript that its executed on document ready(jquery stuff) you must re attach that events when you apply changes to your DOM, you can do it as bert told, or overwriting the method called renderHead,

wathever wicket implements a table with order via ajax see http://wicketstuff.org/wicket14/repeater/

Upvotes: 0

bert
bert

Reputation: 7696

The real problem here is that sorttable.js (at least the version I found) is not realy intended for this. You do can attach javascript calls to the end of an Ajax call. See my result at github.

Basically, you need to add this to the AjaxSubmitLink that reloads the ListView:

target.appendJavaScript("sorttable.init();");

The only remaining problem is that sorttable.js somehow prevents itself from being run twice. So I needed to comment out the

if (arguments.callee.done)

check in the init() function. My knowledge of javascript is rather limited. If you know a better way, please let me know.

Upvotes: 4

magomi
magomi

Reputation: 6685

Im not sure for 100 % but I think it is not possible to reload also the javascript within or triggered by this ajax call.

I would use the DefaultDataTable component provided by the wicket framework. It comes with building support for sorting.

Upvotes: 0

Related Questions