mdata with function on multiple columns

mdata with function on multiple columns

MatthewreedMatthewreed Posts: 9Questions: 1Answers: 0
edited December 2012 in DataTables 1.9
Hello,
I need to individually change rendering of three columns values adding span tags and leave original values intact for sorting purposes.
So I tried to apply mData functions on multiple columns, like this:

[code]{ 'aTargets': [ 2 ],
'mData' : function(source, type, val) {
if ('set' === type)
{
source[2] = Number(val);
source.rendered = '';
return;
}
else if('display' === type || 'filter' === type)
{
return source.rendered;
}

return source[2]; }
},
{ 'aTargets': [ 3 ],
'mData' : function(source, type, val) {
if ('set' === type)
{
source[3] = Number(val);
source.rendered = '';
return;
}
else if('display' === type || 'filter' === type)
{
return source.rendered;
}

return source[3]; }
},
{ 'aTargets': [ 4 ],
'mData' : function(source, type, val) {
if ('set' === type)
{
source[4] = Number(val);
source.rendered = '';
return;
}
else if('display' === type || 'filter' === type)
{
return source.rendered;
}

return source[4]; }
}[/code]

My problem is that third mData definition somehow overwrites the previous ones so my table displays third column rendering in the previous ones; moreover only the first columns is sorted correctly.

Could you address me to the mistake I'm doing?

Thanks in advance for your kind answers.

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    > source.rendered

    You are storing the rendered item in the same place for all three functions - hence the overwriting. I'd suggest using a different parameter for each - `rendered4` perhaps?

    Allan
  • MatthewreedMatthewreed Posts: 9Questions: 1Answers: 0
    You are true; thanks for your suggestion.
This discussion has been closed.