lightoverhead has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks:

I have question regarding using CGI::Ajax.

my CGI::Ajax registered function will return a table, and I want to control the table's style by using jquery plugin tablesorter

the result table is returned, but I just can not control the style of it, i.e, I can not sort the table with using the plugin tablesorter in calling function

major part of code is as below, these are just part of the code, if there are some punctuation problems, please ignore it

as you can see, the main program, "show_html", can sort the table, "metatable"; however, the return table, "resulttable" can not be sorted even if I put id='resulttable' there.

Could someone help me with this issue?

Thank you

my $cgi = CGI->new(); my $pjx = CGI::Ajax->new('js_fun'=>\&perl_fun); sub per_fun{ ... print $cgi->start_table({id=>'resulttable'}), ... } sub show_html{ //partial code print $html_fh $cgi->start_html( -title=>'Selected GEO MetaData', -style=> {-src=>[ "jquery-ui-1.8.20.custom.css", "jq_tablesorter/themes/green/style.css", "jq_ui_redmond/css/selectable.css", ] }, -script=>[ { -type => "text/javascript", -src => "$tempdir/jq/js/jquery-1.7.2.min.js" }, { -type => 'text/javascript', -src => "$tempdir/jq/jq_tablesorter/jquery.tablesort +er.min.js" }, { -type => 'text/javascript', -src => "$tempdir/jq/jq_ui_redmond/js/jquery-ui-1.8. +20.custom.min.js" }, q< $(document).ready(function(){ $("#metatable").tablesorter(); $("#resulttable").tablesorter(); )} .... $("#done").click(function(){ $("#metatable").slideUp(); js_fun(['val1'],['result1']); //ajax return false; }) ..... print $cgi->div({id=>'result1'}); ..... }

Replies are listed 'Best First'.
Re: CGI::Ajax can not control returned table css style
by Corion (Patriarch) on May 12, 2012 at 19:12 UTC

    What part of your problem relates to Perl?

    Does Perl output the correct HTML? If no, then you will need to show us the HTML you expect, and the HTML you get, and tell us where they differ.

    I suspect that your problem only relies on the Javascript side of things. If you replace an item on the Javascript DOM, you need to rebind all the events you want on it.

      Thank you Corion.

      The perl script actually output the correct table

      The problem I encountered is that this table can not be sorted by tablesorter plugin evenif I have printed an id='resulttable' for this returned table.

        Maybe you want http://jquerymonks.org? You will need to learn how to re-bind events on to Javascript DOM objects. This has nothing to do with Perl, so please don't ask Javascript (or jQuery) questions here.

        A reply falls below the community's threshold of quality. You may see it by logging in.