mdata with function on multiple columns
mdata with function on multiple columns
Matthewreed
Posts: 9Questions: 1Answers: 0
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.
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.
This discussion has been closed.
Replies
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