JQuery DataTable is easy to search with paging, sorting on HTML table.

Now I am going to create an HTML Page with some data using HTML Table.

HTML Code:

  1. <html>
  2. <head>
  3. <title>Using Jquery Datatabble</title>
  4. <head>
  5. <body>
  6. <table id="datatable">
  7. <thead>
  8. <tr>
  9. <th>
  10. Username
  11. </th>
  12. <th>
  13. Password
  14. </th>
  15. <th>
  16. Created by
  17. </th>
  18. </tr>
  19. </thead>
  20. <tbody>
  21. <tr>
  22. <td>
  23. Vinodh
  24. </td>
  25. <td>
  26. jquery@123
  27. </td>
  28. <td>
  29. Admin
  30. </td>
  31. </tr>
  32. <tr>
  33. <td>
  34. Santhakumar
  35. </td>
  36. <td>
  37. jquery@123
  38. </td>
  39. <td>
  40. Guest
  41. </td>
  42. </tr>
  43. </tbody>
  44. </table>
  45. </body>
  46. </html>
Run in browser.

Output look like the following,

output
Now I will add a JQuery references for DataTtable:

Download all these references and include it into your html page.

Add this simple script to call the JQuery DataTable.

  1. <script type="text/javascript">
  2. $(document).ready(function()
  3. {
  4. $('#datatable').dataTable
  5. ({
  6. /Get the ID of the table
  7. });
  8. });
  9. </script>
Full Code:
  1. <html>
  2. <head>
  3. <title>Using Jquery Datatable</title>
  4. <head>
  5. <script src="https://code.jquery.com/jquery-1.11.3.min.js" type="text/javascript"></script>
  6. <script src="https://cdn.datatables.net/1.10.9/js/jquery.dataTables.min.js" type="text/javascript"></script>
  7. <link rel="stylesheet" href="https://cdn.datatables.net/1.10.9/css/jquery.dataTables.min.css" />
  8. <script type="text/javascript">
  9. $(document).ready(function() {
  10. $('#datatable').dataTable({});
  11. });
  12. </script>
  13. </script>
  14. </head>
  15. <body>
  16. <table id="datatable">
  17. <thead>
  18. <tr>
  19. <th>
  20. Username
  21. </th>
  22. <th>
  23. Password
  24. </th>
  25. <th>
  26. Created by
  27. </th>
  28. </tr>
  29. </thead>
  30. <tbody>
  31. <tr>
  32. <td>
  33. Vinodh
  34. </td>
  35. <td>
  36. jquery@123
  37. </td>
  38. <td>
  39. Admin
  40. </td>
  41. </tr>
  42. <tr>
  43. <td>
  44. Santhakumar
  45. </td>
  46. <td>
  47. jquery@123
  48. </td>
  49. <td>
  50. Guest
  51. </td>
  52. </tr>
  53. </tbody>
  54. </table>
  55. </body>
  56. </html>
Now finally the output looks like this.

I will search for “Vinodh”.

output

You can see the result above.