Quantcast
Channel: Recent Discussions — DataTables forums
Viewing all articles
Browse latest Browse all 82130

mdata with function on multiple columns

$
0
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:

{ 'aTargets': [ 2 ],  
                                'mData'    : function(source, type, val) {
                                                if ('set' === type) 
                                                {
                                                    source[2] = Number(val);
                                                    source.rendered = '<span class="indicator"><span title="' + ((0 === source[2])? realTimeMonitor.fault0Title : (source[2] + ' ' + realTimeMonitor.fault1Title)) + '" class="' + ((0 === source[2])? 'green' : 'red') + '"></span></span>';
                                                    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 = '<span class="indicator"><span title="' + ((0 === source[3])? realTimeMonitor.threshold0Title : (source[3] + ' ' + realTimeMonitor.threshold1Title)) + '" class="' + ((0 === source[3])? 'green' : 'red') + '"></span></span>';
                                                    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 = '<span class="indicator"><span title="' + ((0 === source[4])? realTimeMonitor.network0Title : ((1 === source[4])? realTimeMonitor.network1Title : realTimeMonitor.network01Title)) + '" class="' + ((0 === source[4])? 'grey' : ((1 === source[4]) ? 'green' : 'red')) + '"></span></span>';
                                                    return;
                                                }
                                                else if('display' === type || 'filter' === type) 
                                                {
                                                    return source.rendered;
                                                }
                                                
                                                return source[4]; }
                               }

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.

Viewing all articles
Browse latest Browse all 82130

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>