Dynamic data is not working in DataTables
Dynamic data is not working in DataTables
I made a table and I have been using Datatable CDN to have some functions such as search and the ability to select table pages. After following the steps on DataTables my code load my table with the search bar and pages, however all the functions are not working. Can someone tell me where I did a mistake please:
Using static data makes the dataTable work as it is intended with the search option and pagination working and showing the results that are in the table. However when using dynamic data with MySQL database the search and pagination functions stops working. Below is my code with fetch the data from table employees from my DB:
<?php
global $db;
$sql = "SELECT id, name, role, competency FROM employees";
$result = mysqli_query($db, $sql);
<?php
>
```
?>
This query is found just before my table in my html code, all the data are displayed correctly and styling of dataTable are displayed also, however the functions for search and pagination are not working. The search returns No Match result however the record is present in the table. Can someone please tell me the error please.
ID | Employee Name | Job Role | Competency Level | Action |
<?php echo $row['id']; ?> | <?php echo $row['name']; ?> | <?php echo $row['role']; ?> | <?php echo $row['competency']; ?> | View Update " required> Delete |
In my code I have also included the script that would use DataTables as follows:
```
and the style link for the datatable
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.25/css/dataTables.bootstrap5.min.css">
```
I have also initiated the DataTable function at the end of my html code in my script as follows:
$(document).ready(function(){
$('#Data_Table').DataTable();
});
```
All the style are working as intended but the function such as search and pagination are not working can someone tell me what i made wrong here
Answers
We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.
Cheers,
Colin