javascript - jQuery pagination next and previous buttons are not working -
please me custom dynamic pagination next , previous. here work available in example. have given in static page. actually, trying dynamic page. please guide me pagination
<table id="mytable"> <thead> <tr> <th>s.no</th> <th>category</th> <th>product</th> <th>price</th> <th>status</th> </tr> </thead> <tbody> <tr> <td>1</td> <td>clothing</td> <td>north jacket</td> <td>$189.99</td> <td>in-stock</td> </tr> <tr> <td>2</td> <td>shoes</td> <td>nike</td> <td>$59.99</td> <td>in-stock</td> </tr> <tr> <td>3</td> <td>electronics</td> <td>led tv</td> <td>$589.99</td> <td>out of stock</td> </tr> <tr> <td>4</td> <td>sporting </td> <td>ping golf </td> <td>$159.99</td> <td>in-stock</td> </tr> <tr> <td>5</td> <td>clothing</td> <td>sweater</td> <td>$19.99</td> <td>in-stock</td> </tr> <tr> <td>6</td> <td>clothing</td> <td>north jacket</td> <td>$189.99</td> <td>in-stock</td> </tr> <tr> <td>7</td> <td>shoes</td> <td>nike</td> <td>$59.99</td> <td>in-stock</td> </tr> <tr> <td>8</td> <td>electronics</td> <td>led tv</td> <td>$589.99</td> <td>out of stock</td> </tr> <tr> <td>9</td> <td>sporting</td> <td>ping golf</td> <td>$159.99</td> <td>in-stock</td> </tr> <tr> <td>10</td> <td>shoes</td> <td>nike</td> <td>$59.99</td> <td>in-stock</td> </tr> <tr> <td>11</td> <td>electronics</td> <td>led tv</td> <td>$589.99</td> <td>out of stock</td> </tr> <tr> <td>12</td> <td>sporting </td> <td>north jacket </td> <td>$159.99</td> <td>in-stock</td> </tr> </tbody>
$('#mytable').after('<nav id="nav" style="display:inline;width:350px;"><ul class="pagination" style="margin: 2px 0 0;"></ul></nav>'); var rowsshown = 5; var rowstotal = $('#mytable tbody tr').length; var numpages = math.round(rowstotal/rowsshown); console.log("mat",math.round(numpages) ); $('.pagination').append('<li><a id="previous" href="#" aria-label="previous"><span aria-hidden="true">«</span></a></li>'); for(i = 0;i < numpages;i++) { var pagenum = + 1; console.log("te",pagenum); $('.pagination').append('<li><a id="tot1"href="#" rel="'+i+'">'+pagenum+'</a></li>'); console.log("i", pagenum, numpages) if(i == numpages -1){ $('.pagination').append('<li><a href="#" aria-label="next"><span aria-hidden="true">»</span></a></li>'); } } $('#mytable tbody tr').hide(); $('#mytable tbody tr').slice(0, rowsshown).show(); //$('#nav a:first').addclass('active'); $('.pagination a').bind('click', function(){ $('.pagination a').removeclass('active'); //$(this).addclass('active'); var currpage = $(this).attr('rel'); console.log("curnt",currpage); var startitem = currpage * rowsshown; var enditem = startitem + rowsshown; $('#mytable tbody tr').css('opacity','0.0').hide().slice(startitem, enditem). css('display','table-row').animate({opacity:1}, 300); });
thanks in advance
try
$('.pagination a').bind('click', function(){ $('.pagination a').removeclass('active'); //$(this).addclass('active'); if($(this).attr("aria-label") == "next") { hf_page.value=parseint(hf_page.value)+1; var startitem = hf_page.value * rowsshown; var enditem = startitem + rowsshown; } else if ($(this).attr("aria-label") == "previous") { hf_page.value=parseint(hf_page.value)-1 var startitem = (hf_page.value) * rowsshown; var enditem = startitem + rowsshown; } else { var currpage = $(this).attr('rel'); console.log("curnt",currpage); var startitem = currpage * rowsshown; var enditem = startitem + rowsshown; hf_page.value = currpage; }
Comments
Post a Comment