I have this code listing, i would like to add a link to datatables, I am getting an error: DataTables warning (table id = 'example'): Requested unknown parameter '3' from the data source for row 0, When i click ok, it does not load the link i have added, Here is my code
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
var oTable = $('#example').dataTable( {
"bProcessing": true,
"sAjaxSource": "<?php echo base_url('operations/dataDisplayBanks/'); ?>",
"aoColumns": [
{ "mData": "bank_id" },
{ "mData": "bank_name" },
{ "mData": "absolute_amount" },
{
"fnRowCallback": function( nRow, aData, iDisplayIndex ) {
$('td:eq(3)', nRow).html('<?php echo base_url() ?>operations/display/' + aData[0] + '">' +
aData[0] + '</a>');
return nRow;
}
},
]
} );
} );
</script>
<div id="demo">
<table cellpadding="0" cellspacing="0" border="0" class="display" id="example">
<thead>
<tr>
<th>Client ID</th>
<th>Client Name</th>
<th>Absolute Limit</th>
<th>History</th>
</tr>
</thead>
<tbody>
</tbody>
<tfoot>
</table>
</div>
EDIT i meant to say mRender is preferred for use over FnRowCallback on server-side implementations to create urls from data
here is an example using your code, add it and remove the FnRowCallback
Docs: http://www.datatables.net/release-datatables/examples/advanced_init/column_render.html
You need an entry in
aoColumns
for the history property, that should solve there error you're seeing. Datatables expects a value for every column in the table, even if you plan on setting that value programmatically. I haven't found a way around this.Also, your
fnRowCallback
shouldn't be a part ofaoColumns
.fnRowCallback
should be part of the datatables configuration object (i.e., a peer ofaoColumns
).Your config will look something like this:
Your data will look something like this: