comparing values and update?

comparing values and update?

mosstraumosstrau Posts: 3Questions: 0Answers: 0
edited January 2014 in General
hey,

i got a list with prices. when a price changes the table gets updated with fnAjaxReload
how can i compare the updated value with the old one?

i tried fnRowCallback but the 'old_value' is always the new one..


my code:

[code]
var oTable = $('#table').dataTable(
{
"sAjaxSource" : "http://192.168.100.163:8888/datatables",
"iDisplayLength" : 2,
"bProcessing": true,
"bServerSide": true,
"bSort": true,
"bInfo": true,
"bPaginate": true,
"bLengthChange": false,
"bStateSave": false, //true for save location
"bFilter": false,
"bAutoWidth": false,
"aaSorting": [[ 4, "desc" ], [ 5, "asc" ]],
"oLanguage": { "sProcessing": "" },
"aoColumnDefs":
[
{ "bVisible": false, "aTargets": [0] },
{ "bVisible": false, "aTargets": [1] },
{ "bVisible": false, "aTargets": [2] },
{ "bVisible": false, "aTargets": [3] },
{ "bVisible": true, "aTargets": [4] },
{ "bVisible": true, "aTargets": [5] },
{ "bVisible": false, "aTargets": [6] },
{ "bVisible": true, "aTargets": [7] }
],
"fnRowCallback": function(nRow, aData, iDisplayIndex, iDisplayIndexFull)
{
var old_value = $('td:eq(1)', nRow).html();
var new_value = aData[5];
console.log('old value: '+old_value);
console.log('new value: '+new_value);

if (old_value > new_value) { console.log("bigger"); }
if (old_value < new_value) { console.log("smaller"); }
if (old_value == new_value) { console.log("same"); }
}
});
setInterval(function() { oTable.fnReloadAjax(); },5000);
[/code]

thanks in advance,
mosstrau

Replies

  • mosstraumosstrau Posts: 3Questions: 0Answers: 0
    any1?
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    You would need to intercept the Ajax call (possibly by modifying fnReloadAjax?) and store the data on each get so you can then compare it later on. As you say, DataTables doesn't keep the old data (there is no reason why it would!).

    Allan
  • mosstraumosstrau Posts: 3Questions: 0Answers: 0
    hey allan,

    i have no idea what to modify inside fnReloadAjax :(
    i just wanna compare the old value with the updated one and highlight the row..

    i love datatables but i will need to search for some other table plugin that supports such a function..

    greetz,
    mosstrau
This discussion has been closed.