views:

108

answers:

0

I'm using this jQuery plugin to turn a CSV file into a table. I then want to paginate the results. I know I should probably do it server side but I'm curious to see if its possible client side.

<script type="text/javascript">
$(document).ready(function(){
$('#view1').csv2table('Book1.csv');

$('table').each(function() {
    var currentPage = 0;
    var numPerPage = 100;
    var $table = $(this);
    var repaginate = function() {
     $table.find('tbody tr').hide()

      .slice(currentPage * numPerPage,
      (currentPage + 1) * numPerPage)
      .show();
     $table.find('tr:eq(0)').show()
     };
    var numRows = $table.find('tbody tr').length;
    var numPages = Math.ceil(numRows / numPerPage);
    var $pager = $('<div class="pager"></div>');
     for (var page = 0; page < numPages; page++) {
      $('<span class="page-number"></span>').text(page + 1)
       .bind('click', {newPage: page}, function(event) {
        currentPage = event.data['newPage'];
        repaginate();
        $(this).addClass('active')
       }).appendTo($pager).addClass('clickable');
      }
      $pager.insertBefore($table)
      .find('span.page-number:first').addClass('active');
     });

});

How do I run the paginate function AFTER the plugin has done its work?