0

I've been trying to use numerous jQuery plugins for tabling sorting in WordPress and have had absolutely no luck. Can anyone make a suggestion for a plugin that sorts tables of dynamic content?

I'm using the following code to generate the table:

$args=array(
'post_type' => 'page',
 'post_status' => 'publish',
 'cat'      => 1,
 'posts_per_page' => 10,
 'caller_get_posts'=> 1
);
$c = 0;
$my_query = null;
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {  ?>`

<table id="actArchive" class="tablesorter activity-archives" summary="This is the activities archive table">
<thead> 
  <tr>
   <th>Activity</th>
   <th>Episode</th>
   <th>Learning Goal</th>
   <th>Description</th>
 </tr>
</thead> 
<?php
  while ($my_query->have_posts()) : $my_query->the_post();
$epititle = get_post_meta($post->ID, '_pbsparents_rept', true);
$learninggoal = get_post_meta($post->ID, '_pbsparents_replg', true);
$description = get_post_meta($post->ID, '_pbsparents_actshortdesc', true); ?>
  <tbody> 
    <tr class="<?=($c++%2==1) ? 'odd' : 'even' ?>">
       <td><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></td>
       <td><?php echo $epititle; ?></td>
       <td><?php echo $learninggoal; ?></td>
       <td><?php echo $description; ?></td>
    </tr>
</tbody> 
<?php endwhile; ?>
</table>
<?php }
wp_reset_query();

Currently I'm attempting to use tablesorter.js to sort things and I've got everything working but when I click on the headings I want to sort, nothing happens.

On edit: Posting jQuery

$js162(function(){
  $js162("table").tablesorter({
     headers: {
     0: { sorter: "text" },
     1: { sorter: "digit" },
     2: { sorter: false },
     3: { sorter: false }
    }
 });
});
7
  • If you are successfully pulling data out of the WordPress tables, then this question isn't a WordPress question, but rather a jQuery question. Apr 4, 2012 at 17:14
  • okay, thanks! I didn't know if maybe I was doing something wrong on the WP end. Apr 4, 2012 at 17:56
  • Well, absent the jQUery, are you getting tabular data as you're expecting? Apr 4, 2012 at 19:17
  • Yes, I am and I did some research that intimated that it may have something to do with the dynamic data. That's why I asked here first. Apr 4, 2012 at 19:48
  • There may be other ways, but I can foresee two ways in which this issue might be WordPress-related: 1) the querying of the data itself, and 2) WordPress's use of no-conflict mode for jQuery. If you're getting your tabular data, I'm pretty sure you don't have a problem with querying the data (dynamic or otherwise), since at this point, you're looking at plain-old rendered, tabular, HTML content. So, I'd next look at whether your jQuery scripts use no-conflict mode. Apr 4, 2012 at 19:57

1 Answer 1

1

You might try calling the table by ID instead of the generic 'table'. Also, wrap your JS in a noconflict wrapper like this:

(function($) {
    $js162(function(){
      $js162("#actArchive").tablesorter({
         headers: {
         0: { sorter: "text" },
         1: { sorter: "digit" },
         2: { sorter: false },
         3: { sorter: false }
        }
     });
    });
})(jQuery);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.