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
-
- <?php require_once("includes/connection.php"); ?>
- <?php require_once("includes/functions.php"); ?>
- <?php include_once("includes/form_functions.php");?>
- <?php include_once("includes/html.php");?>
- <?php include_once("includes/pagination.php");?>
- <?php
- echo @get_country();//members array to be used to populate table
- ?>
- <script type="text/javascript">
-
-
-
-
- // This file demonstrates the different options of the pagination plugin
- // It also demonstrates how to use a JavaScript data structure to
- // generate the paginated content and how to display more than one
- // item per page with items_per_page.
-
- /**
- * Callback function that displays the content.
- *
- * Gets called every time the user clicks on a pagination link.
- *
- * @param {int}page_index New Page index
- * @param {jQuery} jq the container with the pagination links as a jQuery object
- */
- function pageselectCallback(page_index, jq){
- // Get number of elements per pagionation page from form
- var newcontent ='';
- var items_per_page = $('#items_per_page').val();
- var max_elem = Math.min((page_index+1) * items_per_page, <?php echo @country_count_all(); ?>);
- var newcontent = '<thead><tr><th>Nome</th><th>Nome Local</th></tr><thead>';
- // Iterate through a selection of the content and build an HTML string
-
- for(var i=page_index*items_per_page;i<max_elem;i++)
- {
- newcontent += '<tr>';
- newcontent += '<td>' + members[i][0] + '</td>';
- newcontent += '<td>' + members[i][1] + '</td>';
- newcontent += '</tr>';
- }
-
- // Replace old content with new content
- $('#Searchresult').html(newcontent);
-
- // Prevent click eventpropagation
- return false;
- }
-
- // The form contains fields for many pagiantion optiosn so you can
- // quickly see the resuluts of the different options.
- // This function creates an option object for the pagination function.
- // This will be be unnecessary in your application where you just set
- // the options once.
- function getOptionsFromForm(){
- var opt = {callback: pageselectCallback};
- // Collect options from the text fields - the fields are named like their option counterparts
- $("input:text").each(function(){
- opt[this.name] = this.className.match(/numeric/) ? parseInt(this.value) : this.value;
- });
- // Avoid html injections in this demo
- var htmlspecialchars ={ "&":"&", "<":"<", ">":">", '"':"""}
- $.each(htmlspecialchars, function(k,v){
- opt.prev_text = "Anterior";//opt.prev_text.replace(k,v);
- opt.next_text = "Seguinte"; //opt.next_text.replace(k,v);
- })
- return opt;
- }
-
- // When document has loaded, initialize pagination and form
- $(document).ready(function(){
- // Create pagination element with options from form
- var optInit = getOptionsFromForm();
- $("#Pagination").pagination(<?php echo @country_count_all(); ?>, optInit);
-
- // Event Handler for for button
- $("#setoptions").click(function(){
- var opt = getOptionsFromForm();
- // Re-create pagination content with new parameters
- $("#Pagination").pagination(<?php echo @country_count_all(); ?>, opt);
- });
-
- });
-
- </script>
- <div id="site_content">
-
- <div id="content">
-
- <div class="registos"><?php echo @country_count_all(); ?> Registos</div>
-
- <table class="tablesorter" style='width:100%; border-spacing:0;' id="Searchresult">
-
- </table>
- <div id="Pagination" class="pagination"></div>
- <div style="display:none;">
- <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"/>
- <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"/>
- </div>
- </div>
- <div class="clearFix"></div>
- </div>
And the function
@get_country()
-
- function get_country(){
- global $connection;
- $filter = $_SESSION['registry'];
- $script = "";
- $script = "<script type=\"text/javascript\" >
- var members = [";
- $query = "SELECT country.Name, country.LocalName
- FROM country";
- $result_set = mysql_query($query);
- //$numRows = mysql_num_rows($result_set);
- //echo $query;
- while($data = mysql_fetch_array($result_set)){
- $script .= "[";
- $script .= "'".$data['Name']."', ";
- $script .= "'".$data['LocalName']."' ";
- $script .= "],";
- }
- $script .="]</script>";
-
- return $script;
- }
I made several attempts to make this work and unfortunately none was successful.
Tks in advance