I have a DataTable and I set a cells value through its object.
I don't want to set the cells values directly through jQuery because of other problems found here
How can I set different values for the filtering and ordering of that cell like it can be achieved when you load orthogonal data or when you use HTML5 data-... attributes
Here's a code snippet for better understanding the problem - click to sort by speed after running it
$(document).ready(function() {
var dt = $('#example').DataTable({});
//this is not enough as the change doesn't reflect on sorting and filtering
dt.cell( $("#obj2_speed") ).data(9 + 'km/h') ;
//this doesn't work like I would like to
/*dt.cell( $("#obj1_speed") ).data({
"_": 7 + 'km/h',
"sort": 7,
"filter": 'seven'
});*/
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdn.datatables.net/1.10.15/js/jquery.dataTables.min.js"></script>
<link href="https://cdn.datatables.net/1.10.15/css/jquery.dataTables.min.css" rel="stylesheet"/>
<table id="example" class="display" width="100%" cellspacing="0">
<thead>
<tr>
<th>Object</th>
<th>Speed</th>
</tr>
</thead>
<tbody>
<tr>
<td>object 1</td>
<td id="obj1_speed" data-sort="80" data-filter="eighty">80km/h</td>
</tr>
<tr>
<td>object 2</td>
<td id="obj2_speed" data-sort="8" data-filter="eight">8km/h</td>
</tr>
<tr>
<td>object 3</td>
<td id="obj3_speed" data-sort="90" data-filter="ninety">90km/h</th>
</tr>
</tbody>
</table>
My use case for the above sounds something like this:
I initially load the DataTable from a database but then I have to do repeated ajax requests which need to update different portions of the DataTable, and those updates need to be reflected inside it.
Say I keep my browser open on my page which displays my DataTable sorted by speed. After 5 seconds an ajax request/response comes in and updates the speed of a cell. I want that updated and the row moved upwards or downwards because I'm looking at it ordered by speed. I already achieved that but with small shortcomings given by the fact that "8km/h" is a string and won't get ordered correctly with "80km/h" and "90km/h"