I want to loop through columns on datatable. Check the class of the header and set the width of the column.
As per DataTables docs. This is how you loop through the header but how can I set the column width?
<table id="data-table">
<thead>
<tr>
<th>ID</th>
<?php if ($client) : ?>
<th class="client">Client</th>
<?php endif; ?>
<th>Product</th>
</tr>
</thead>
<tbody>
<tr>
<td><?php echo $id; ?></td>
<?php if ($client) : ?>
<td><?php echo $client; ?></td>
<?php endif; ?>
<td><?php echo $product; ?></td>
</tr>
</tbody>
</table>
<script>
var myTable = $('#data-table').DataTable();
myTable.columns().header().each(function(value, index){
if ( $(value).hasClass('client') ) {
// Set column width here
}
})
</script>