I am using the jquery datatables plugin and codeigniter. In one of my views I have:
<table id="myDataTable" class="display" cellspacing="0" width="100%">
<thead>
<tr>
<?php foreach($keys as $key): ?>
<th><?php echo $key; ?></th>
<?php endforeach; ?>
</tr>
</thead>
<tbody>
</tbody>
</table>
<script type="text/javascript">
$(document).ready(function () {
var oTable = $('#big_table').dataTable({
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": 'datatable_controller/datatable',
"sPaginationType": "full_numbers",
"columns": [
{ "data": "id" },
{ "data": "message_id" },
{ "data": "subject" },
{ "data": "date" }
],
in reference to the columns structure, right now I am hard coding in column field names (id, message-id,subject , date ) . I already have these in an array $keys, which I am using above to dynamically generate the table HTML. Is there a way to pass $keys directly into the "columns" option?