0

Can I make a table with navigation?

So, if I have a 20 tr in my table, and I just want to show 10 data, and then the table have a next button to next data. Can I do that?

I make it in Java (I make jsp page)

try {
    int i = 1;
    while (hasilQuery.next()) {
      hasil += "<tr><td>" + i + "</td><td>" + hasilQuery.getString("nik")
             + "</td><td>" + hasilQuery.getString("nama")
             + "</td><td>" + hasilQuery.getString("jeniskelamin")
             + "</td>"
             + "<td><a href='detail.jsp?nik="+hasilQuery.getString("nik")+"'"
             + "><img height='20' src='img/detail.png' title='detail' /></a><a href='edit.jsp?nik="+hasilQuery.getString("nik")+"'><img src='img/edit.png' height='20' title='edit' /></a> "
             + "<a href='delete.jsp?nik="+hasilQuery.getString("nik")+"'><img src='img/hapus.png' height='20' title-'hapus' /></a></td></tr>";
   i++;
}
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
julian nr
  • 39
  • 10
  • Hope the [post](http://stackoverflow.com/questions/19605078/how-to-use-pagination-on-html-tables) will guide you for a solution. – sureshunivers May 02 '16 at 10:18

2 Answers2

0
while (hasilQuery.next()) {

As well as stopping when you run out of results, stop when you have hit 10 results.

Then, if you haven't run out of results, add a link at the end:

<a href="?page=2">Page 2</a>

Now go back to the top of the code and check that query string parameter. If you have a value for it, use it to skip an appropriate number of results before you start outputting.

Then just change the "2" to be a dynamic value (also based on the value used to request the page). You'll probably want to add a previous link too.

… and that's the basics.


You'll probably want to move the logic for finding the 10 items you want into the database query instead of fetching all the results and then skipping a bunch in the Java.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
-1

You could use jQuery detach() to remove rows and insert them at the click event of your button.

Jabba Da Hoot
  • 794
  • 2
  • 7
  • 16