Using tablesorter jquery plugin on table with jquery ypagination

Using tablesorter jquery plugin on table with jquery ypagination

This is the table sorter i desire to implement, if that's possible.


This is my scenario


With the following code


  1. <?php require_once("includes/connection.php"); ?>   
  2. <?php require_once("includes/functions.php"); ?>
  3. <?php include_once("includes/form_functions.php");?>
  4. <?php include_once("includes/html.php");?>
  5. <?php include_once("includes/pagination.php");?>
  6. <?php
  7. echo @get_country();//members array to be used to populate table
  8. ?>
  9.   <script type="text/javascript">








  10.             // This file demonstrates the different options of the pagination plugin
  11.             // It also demonstrates how to use a JavaScript data structure to
  12.             // generate the paginated content and how to display more than one
  13.             // item per page with items_per_page.


  14.             /**
  15.              * Callback function that displays the content.
  16.              *
  17.              * Gets called every time the user clicks on a pagination link.
  18.              *
  19.              * @param {int}page_index New Page index
  20.              * @param {jQuery} jq the container with the pagination links as a jQuery object
  21.              */
  22.             function pageselectCallback(page_index, jq){
  23.                 // Get number of elements per pagionation page from form
  24.                 var newcontent ='';
  25.                 var items_per_page = $('#items_per_page').val();
  26.                 var max_elem = Math.min((page_index+1) * items_per_page, <?php echo @country_count_all(); ?>);
  27.                 var newcontent = '<thead><tr><th>Nome</th><th>Nome Local</th></tr><thead>';
  28.                 // Iterate through a selection of the content and build an HTML string
  29.                 
  30.                 for(var i=page_index*items_per_page;i<max_elem;i++)
  31.                 {
  32.                     newcontent += '<tr>';
  33.                     newcontent += '<td>' + members[i][0] + '</td>';
  34.                     newcontent += '<td>' + members[i][1] + '</td>';
  35.                     newcontent += '</tr>';
  36.                 }


  37.                 // Replace old content with new content
  38.                 $('#Searchresult').html(newcontent);


  39.                 // Prevent click eventpropagation
  40.                 return false;
  41.             }


  42.             // The form contains fields for many pagiantion optiosn so you can
  43.             // quickly see the resuluts of the different options.
  44.             // This function creates an option object for the pagination function.
  45.             // This will be be unnecessary in your application where you just set
  46.             // the options once.
  47.             function getOptionsFromForm(){
  48.                 var opt = {callback: pageselectCallback};
  49.                 // Collect options from the text fields - the fields are named like their option counterparts
  50.                 $("input:text").each(function(){
  51.                     opt[this.name] = this.className.match(/numeric/) ? parseInt(this.value) : this.value;
  52.                 });
  53.                 // Avoid html injections in this demo
  54.                 var htmlspecialchars ={ "&":"&amp;", "<":"&lt;", ">":"&gt;", '"':"&quot;"}
  55.                 $.each(htmlspecialchars, function(k,v){
  56.                     opt.prev_text = "Anterior";//opt.prev_text.replace(k,v);
  57.                     opt.next_text = "Seguinte"; //opt.next_text.replace(k,v);
  58.                 })
  59.                 return opt;
  60.             }


  61.             // When document has loaded, initialize pagination and form
  62.             $(document).ready(function(){
  63.                 // Create pagination element with options from form
  64.                 var optInit = getOptionsFromForm();
  65.                 $("#Pagination").pagination(<?php echo @country_count_all(); ?>, optInit);


  66.                 // Event Handler for for button
  67.                 $("#setoptions").click(function(){
  68.                     var opt = getOptionsFromForm();
  69.                     // Re-create pagination content with new parameters
  70.                     $("#Pagination").pagination(<?php echo @country_count_all(); ?>, opt);
  71.                 });


  72.             });


  73.   </script>
  74. <div id="site_content">


  75.     <div id="content">


  76.             <div class="registos"><?php echo @country_count_all(); ?> Registos</div>


  77.               <table class="tablesorter" style='width:100%; border-spacing:0;' id="Searchresult">


  78.               </table>
  79.             <div id="Pagination" class="pagination"></div>  
  80. <div style="display:none;">                        
  81. <label for="items_per_page">Number of items per page</label><input type="text" value="20" name="items_per_page" id="items_per_page" class="numeric"/>
  82. <label for="num">Number of start and end points</label><input type="text" value="2" name="num_edge_entries" id="num_edge_entries" class="numeric"/>
  83. </div>
  84.  </div>
  85. <div class="clearFix"></div>
  86. </div>
And the function @get_country()


  1. function get_country(){
  2. global $connection;
  3. $filter = $_SESSION['registry'];
  4. $script = "";
  5. $script = "<script type=\"text/javascript\" >
  6.         var members = [";
  7.         $query = "SELECT country.Name, country.LocalName
  8.         FROM country";
  9.             $result_set = mysql_query($query);
  10.             //$numRows = mysql_num_rows($result_set);
  11.             //echo $query;
  12.             while($data =  mysql_fetch_array($result_set)){
  13.             $script .= "[";
  14.                $script .= "'".$data['Name']."', ";
  15.                $script .= "'".$data['LocalName']."' ";
  16.                $script .= "],";
  17.             }  
  18.         $script .="]</script>";


  19.     return $script;
  20. }
I made several attempts to make this work and unfortunately none was successful.

Tks in advance