I am new to datatables (http://datatables.net/). I have a requirement of adding column based on the computation from result of my ajax call. I tried below approach but get error ” datatable Requested unknown parameter from the data source for row” . Is this the right approach for this kind of requirement. I’ll really appreciate your help in this regard.
This is how table structure looks:
<table id="result" class="show_hide">
<thead>
<tr>
<th>Time1</th>
<th>Time2</th>
<th>Elapsed Time</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
Here is sample output from my ajax call:
[{
"time1": 12345,
"time2": 56789
},
{
"time1": 2000,
"time2": 3000
}]
This is what I am trying with datatables
$('#result').dataTable({
"sAjaxSource": "http://" + hostname + ":" + port + api,
"sAjaxDataProp": "",
"iDisplayLength": 25,
"bRetrieve": true,
"sPaginationType": "full_numbers",
"aoColumns": [{
"mDataProp": "time1"
},
{
"mDataProp": "time2"
},
{
"mRender": function(data, type, row) {
return (row.time2 - row.time1);
},
"mDataProp": null
}
]
});
I don’t think we need any extra property in return object….I figured out the problem. I was using jquery datatable 1.9.0 but this feature of mRender works with 1.9.4. Upgraded the js and this code works like charm with 1.9.4.