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

sDefaultContent not used in array of objects if intermediate property does not exist

$
0
0
I am passing an array of objects to a datatable and would like to define a column as, for example, "attr1.attr2.attr3"
Further, not all objects are expected to have a value for attr1.attr2.

So I also provide an sDefaultContent parameter.

However the function _fnGetObjectDataFn expects the entire path attr1.attr2.attr3 to be traversable. If attr1.attr2 is "undefined" then an exception will be thrown.

Instead could I suggest that _fnGetObjectDataFn should just return undefined?

A possible patch is

--- jquery.dataTables.js        2011-10-05 15:04:54.000000000 +1300
+++ local-jquery.dataTables.js        2011-10-05 15:01:38.000000000 +1300
@@ -6743,23 +6743,29 @@
                                if ( a.length == 2 )
                                {
                                        return function (data) {
-                                               return data[ a[0] ][ a[1] ];
+                                           try {return data[ a[0] ][ a[1] ];}
+                                            catch(e) {return undefined;}
                                        };
                                }
                                else if ( a.length == 3 )
                                {
                                        return function (data) {
-                                               return data[ a[0] ][ a[1] ][ a[2] ];
+                                            try {return data[ a[0] ][ a[1] ][ a[2] ];}
+                                            catch(e) {return undefined;}
                                        };
                                }
                                else
                                {
                                        return function (data) {
+                                            try
+                                            {
                                                for ( var i=0, iLen=a.length ; i<iLen ; i++ )
                                                {
                                                        data = data[ a[i] ];
                                                }
                                                return data;
+                                            }
+                                            catch(e) {return undefined;}
                                        };
                                }
                        }

Viewing all articles
Browse latest Browse all 81687

Trending Articles



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