Embedding a timer per row

Embedding a timer per row

_rain__rain_ Posts: 4Questions: 0Answers: 0
edited January 2012 in DataTables 1.8
Hi All,

Say, I want to have each row in the datatable its own personal timer. Any ideas on how to implement this?

Tried using this approach, but the value returned under the target column is undefined.

[code]
var oTable = $('#example').dataTable({
"bStateSave": true,
"bJQueryUI": false,
"bProcessing": true,
"sPaginationType": "full_numbers",
/*"sAjaxSource": '../server.side/Query.ashx',*/ // this is just an alternative source
"sAjaxSource": '../data3.txt',
"iDisplayLength": 30,
"bPaginate": true,
"aoColumnDefs": [
{
"fnRender": function (col) {
return col.aData["col1"];
}, "bUseRendered": false, "aTargets": [0], "bSortable": false, "mDataProp": null
},
{
"fnRender": function (col) {
var currentTime = new Date();
var month = currentTime.getMonth() + 1;
var day = currentTime.getDate();
var year = currentTime.getFullYear();
var hours = currentTime.getHours();

var minutes = currentTime.getMinutes();
var seconds = currentTime.getSeconds();
if (minutes < 10) {
minutes = "0" + minutes;
}

setInterval(function () {
if (seconds != 0) {
return seconds;
}

}, 1000);
}, "bUseRendered": false, "aTargets": [1], "bSortable": false, "mDataProp": null
}
]
});
[/code]

Your assistance would be highly appreciated!

Replies

  • allanallan Posts: 63,368Questions: 1Answers: 10,449 Site admin
    A timer relative to what? Now and it continuously updates? How would you do it if you weren't using DataTables? Probably something like setInterval would be best for this, calling fnUpdate with the new values when needed.

    fnRender will run only once for the lifetime of each row (unless you update the date with fnUpdate of course :-) ).

    Allan
  • _rain__rain_ Posts: 4Questions: 0Answers: 0
    Hi Allan,

    Thanks for the input, I appreciate it. (.^_^.)
This discussion has been closed.