I am using DataTables to generate a table. There is a column containing order numbers.
For example: ...
I need every row in this column to have a hyperlink to view/order?id=?
where ?
is the contents of row in the Order No column. For example the first row would be a hyperlink to view/order?id=1321755
etc.
What is the simplest way I can do so?
Here is the code that I am using to initialize the DataTables:
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
$('#example').dataTable( {
"serverSide": true,
"ajax": {
"url": "../server_processing/orders.php",
"type": "POST"
},
"order": [[ 0, "desc" ]]
} );
} );
</script>
<table id="example" class="display" cellspacing="0" width="100%">
<thead>
<tr>
<th>Order No</th>
...
</tr>
</thead>
<tbody>
</tbody>
</table>
I needed to use jQuery dataTables and turn a normal field to be a HREF field.
Here you have it all, including also dataTables error handling..
Enjoy..
Yosi Lev
By Yosi Lev - Feb 22, 2016
Check this out: http://datatables.net/reference/option/columns.render
You can add a column render callback when you specify columns definition.
The data in that column will be changed to what the render function return.