integrate the datatables in html view

  1. Include the necessary libraries: Ensure you have the required libraries (jQuery and DataTables) included in your HTML file. You can link to these libraries from a content delivery network (CDN) or use local files.


<!DOCTYPE html>

<html>

<head>

<title>DataTables Example</title>

<!-- jQuery library -->

<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>

<!-- DataTables CSS -->

<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.11.5/css/jquery.dataTables.css">

<!-- DataTables JS -->

<script type="text/javascript" charset="utf8" src="https://cdn.datatables.net/1.11.5/js/jquery.dataTables.js"></script>

</head>

<body>

<!-- Your table goes here -->

</body>

</html>



2. Create an HTML table: Set up a basic HTML table in your document, which will be converted into a DataTable.

<table id="myDataTable">

  <thead>

    <tr>

      <th>Name</th>

      <th>Age</th>

      <th>Email</th>

    </tr>

  </thead>

  <tbody>

    <tr>

      <td>John Doe</td>

      <td>30</td>

      <td>john@example.com</td>

    </tr>

    <tr>

      <td>Jane Smith</td>

      <td>25</td>

      <td>jane@example.com</td>

    </tr>

    <!-- Add more rows as needed -->

  </tbody>

</table>


3. Initialize DataTables: Finally, you'll need to initialize the DataTable on your table by targeting its ID and calling the DataTable function. This should be placed within a tag at the end of your HTML body.

<script>

$(document).ready(function() {

$('#myDataTable').DataTable();

});

</script>

more features : https://datatables.net/

Sign In or Register to comment.