javascript - Table pagination with jQuery -


i'm trying simulate pagination using jquery , have worked out essential pagination elements can't navigation part work. worked list element not table structure. can please tell me issue?

var show_per_page = 2; var number_of_items = $('tbody').children().size(); var number_of_pages = math.ceil(number_of_items / show_per_page); var current_link = 0;  $('table').after('<div class=controls></div>'); var navigation_html = '<a class="prev" onclick="previous()">...</a>';  while (number_of_pages > current_link) {   navigation_html += '<a class="page" onclick="go_to_page(' + current_link + ')" longdesc="' + current_link + '">' + (current_link + 1) + '</a>';   current_link++; } navigation_html += '<a class="next" onclick="next()">...</a>';  $('.controls').html(navigation_html); $('.controls .page:first').addclass('active');  $('tbody').children().hide(); $('tbody').children().slice(0, show_per_page).show();  function go_to_page(page_num) {   start_from = page_num * show_per_page;   end_on = start_from + show_per_page;    $('tbody').children().hide().slice(start_from, end_on).show();    $('.page[longdesc=' + page_num + ']').addclass('active').siblings('.active').removeclass('active');  }  function previous() {   new_page = current_link - 1;    if ($('.active').prev('.page').length == true) {     go_to_page(new_page);   } }  function next() {   new_page = current_link + 1;    if ($('.active').next('.page').length == true) {     go_to_page(new_page);   }   $("a.prev").show();  } 

demo js fiddle

your code works, has jsfiddle wrapping function names

i ran code on local file, need include jquery.

this whole code used: https://gist.github.com/kepex/4422d441dbd0b71dfd3d

enter image description here


Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -