Just a question about mRender

Just a question about mRender

KbFwthoxvgXsKbFwthoxvgXs Posts: 8Questions: 0Answers: 0
edited April 2013 in General
Hi. I just want to ask some question about 'mRender'.
For some fields I specify it as a function to return some formatted content. Something like this
[code]
"aoColumns": [
{
"mData": "createdDate",
"mRender": function ( data, type, full ) {
console.log("i_"+full.id);
var curDate = new Date(data);
if (curDate.toDateString() == new Date().toDateString()) {
return curDate.getHours()+':'+curDate.getMinutes();
} else {
var day = d_names[curDate.getDay()];
return ''+day[0]+' +curDate.getHours()+':'+curDate.getMinutes();
}
}
},
[/code]
So, when I have, for example 2 records(actually I have 8 records :-)) with ids 42 and 25, I see during table rendering in my firebug console output like this:
[code]
i_42
i_42
i_25
i_25
i_42
i_25
[/code]

So I made a conclusion that during rendering of a table the 'mRender' function is called 3 times for each record.
My simple question is. Is that an optimal way of doing it? mRender (as I understand) gives us a final content to be placed into . Why we should call it three times?

Sorry, I did not dig deep into the code of the dataDables. Maybe it is a right way of doing it. Maybe it does not matter much. Anyway, I do not have a lot of records to be this an performance issue for me. I just asking. Also here is my whole cnfig
[code]
var table = this.$el.dataTable( {
"sDom": "<'row-fluid'<'span6'l><'span6 jqtReload'>r>t<'row-fluid'<'span6'i><'span6'>>",
"bPaginate": true,
"bFilter": true,
"bSort": false,
"bInfo": true,
"bAutoWidth": false,
"bProcessing": true,
"sScrollY": "185px",
"bScrollCollapse": true,
sAjaxSource: "",
sAjaxDataProp: "",
fnServerData: function( sSource, aoData, fnCallback ){
fnCallback(_that.collection.toJSON());
},
"aLengthMenu": [[3, 5, 8, 10, -1], [3, 5, 8, 10, "All"]],
iDisplayLength: -1,
"aoColumns": [
{
"mData": "createdDate",
"mRender": function ( data, type, full ) {
console.log("i_"+full.id);
var curDate = new Date(data);
if (curDate.toDateString() == new Date().toDateString()) {
return curDate.getHours()+':'+curDate.getMinutes();
} else {
var day = d_names[curDate.getDay()];
return ''+day[0]+' '+curDate.getHours()+':'+curDate.getMinutes();
}
}
},
{
"mData": null,
"mRender": function ( data, type, full ) {
if (full.toAddress === undefined) {
return full.fromAddress;
} else {
return full.fromAddress + ' ' + full.toAddress;
}
}
},
{ "mData": "creator" },
{ "mData": "region" },
{ "mData": "state" },
{
"mData": "statusId",
"mRender": function ( data, type, full ) {
return '';
}
}
]
} );
[/code]

Hmm. When setting "bFilter": false, it is only 2 times for each record.

Replies

  • allanallan Posts: 63,520Questions: 1Answers: 10,473 Site admin
    This discussion covers this topic: http://datatables.net/forums/discussion/15136/mrender-called-multiple-times

    Allan
  • KbFwthoxvgXsKbFwthoxvgXs Posts: 8Questions: 0Answers: 0
    Setting "sType": 'string' for each column, made it to be called only once. Thanks, for quick replay!
This discussion has been closed.