I am using DataTables.js to build a very simple table like so:
<table id="table">
<thead>
<tr>
<th>Type</th>
<th>Name</th>
<th>Category</th>
</tr>
</thead>
<tbody>
<?php $query = 'SELECT * FROM tablename'; $total_query = "SELECT COUNT(1) FROM (${query}) AS combined_table"; $total = $wpdb->get_var( $total_query ); $results = $wpdb->get_results( $query.' ORDER BY name ASC ', OBJECT ); foreach ($results as $result) {; ?>
<tr>
<td><?php echo $result->type; ?></td>
<td><?php echo $result->name; ?></td>
<td><?php echo $result->category; ?></td>
</tr>
<?php };?>
</tbody>
</table>
That works well but i need to create two independent select dropdowns on the page that filter Columns 1 (Type) and 3 (Category). Something like so ...
<select id="willfiltertype">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
<select id="willfiltercategory">
<option value="A">A</option>
<option value="B">B</option>
<option value="C">C</option>
</select>
Here is my JS
$(document).ready(function () {
$('#table').DataTable();
});
I am really struggling with the codepens and DataTables.js sites. Any suggestions or examples would really help and be useful on here i think as there isn't much for people that are intermediates.