jQuery: The Write Less, Do More JavaScript Library

tablesorter + AJAX

View: New views
3 Messages — Rating Filter:   Alert me  

tablesorter + AJAX

by sumdog :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hey there,

I've read through several AJAX+tablesorter posts and am still a little confuzzled on this. I am loading an entire table into a div like so:

<div id="mainContent">
        <p>Loading...</p>
</div>

<script type="text/javascript">
   $(document).ready( function() {
         $.get('/ajaxRates',{},
        function(data) {
          $('#mainContent').html(data);
          $('#ratesTable').tablesorter();
        });
   });
</script>

The /ajaxRates URL returns the HTML table. I place it into the div using the function right after it. I then call that new table and apply tablesorter() to it. If I do this to an inplace table, it works fine. It's just the AJAX table I'm having trouble with.

The new table should be fully in the DOM by the time that function returns correct? Is there some other event I need to wait for or attach somehow in order to get this to work correctly?

Thanks
Sumit Khanna
http://penguindreams.org

Re: tablesorter + AJAX

by aquaone :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

try:
$('#mainContent').html(data).find('#ratesTable').tablesorter();



On Mon, Nov 9, 2009 at 20:38, sumdog <sum.notify@...> wrote:

Hey there,

I've read through several AJAX+tablesorter posts and am still a little
confuzzled on this. I am loading an entire table into a div like so:

<div id="mainContent">
       <p>Loading...</p>
</div>

<script type="text/javascript">
  $(document).ready( function() {
        $.get('/ajaxRates',{},
       function(data) {
         $('#mainContent').html(data);
         $('#ratesTable').tablesorter();
       });
  });
</script>

The /ajaxRates URL returns the HTML table. I place it into the div using the
function right after it. I then call that new table and apply tablesorter()
to it. If I do this to an inplace table, it works fine. It's just the AJAX
table I'm having trouble with.

The new table should be fully in the DOM by the time that function returns
correct? Is there some other event I need to wait for or attach somehow in
order to get this to work correctly?

Thanks
Sumit Khanna
http://penguindreams.org
--
View this message in context: http://old.nabble.com/tablesorter-%2B-AJAX-tp26278194s27240p26278194.html
Sent from the jQuery General Discussion mailing list archive at Nabble.com.



Re: tablesorter + AJAX

by sumdog :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Nevermind. My original approach worked. I had just forgotten to use th tags instead of td tags in the thead section of the table in my AJAX call. Silly mistake.  


aquaone wrote:
try:
$('#mainContent').html(data).find('#ratesTable').tablesorter();



On Mon, Nov 9, 2009 at 20:38, sumdog <sum.notify@gmail.com> wrote:

>
> Hey there,
>
> I've read through several AJAX+tablesorter posts and am still a little
> confuzzled on this. I am loading an entire table into a div like so:
>
> <div id="mainContent">
>        <p>Loading...</p>
> </div>
>
> <script type="text/javascript">
>   $(document).ready( function() {
>         $.get('/ajaxRates',{},
>        function(data) {
>          $('#mainContent').html(data);
>          $('#ratesTable').tablesorter();
>        });
>   });
> </script>
>
> The /ajaxRates URL returns the HTML table. I place it into the div using
> the
> function right after it. I then call that new table and apply tablesorter()
> to it. If I do this to an inplace table, it works fine. It's just the AJAX
> table I'm having trouble with.
>
> The new table should be fully in the DOM by the time that function returns
> correct? Is there some other event I need to wait for or attach somehow in
> order to get this to work correctly?
>
> Thanks
> Sumit Khanna
> http://penguindreams.org
> --
> View this message in context:
> http://old.nabble.com/tablesorter-%2B-AJAX-tp26278194s27240p26278194.html
> Sent from the jQuery General Discussion mailing list archive at Nabble.com.
>
>