hazelnuts with checkboxes enabled can be sorted by that column - e.g. to see users...
[myslice.git] / plugins / hazelnut / static / js / hazelnut.js
index 12ee398..89275ee 100644 (file)
                 // XXX use $.proxy here !
             };
             // the intention here is that options.datatables_options as coming from the python object take precedence
-            //  XXX DISABLED by jordan: was causing errors in datatables.js     $.extend(actual_options, options.datatables_options );
+           // xxx DISABLED by jordan: was causing errors in datatables.js
+           // xxx turned back on by Thierry - this is the code that takes python-provided options into account
+           // check your datatables_options tag instead 
+           $.extend(actual_options, this.options.datatables_options );
             this.table = this.elmt('table').dataTable(actual_options);
 
             /* Setup the SelectAll button in the dataTable header */
 
     $.plugin('Hazelnut', Hazelnut);
 
+  /* define the 'dom-checkbox' type for sorting in datatables 
+     http://datatables.net/examples/plug-ins/dom_sort.html
+     using trial and error I found that the actual column number
+     was in fact given as a third argument, and not second 
+     as the various online resources had it - go figure */
+    $.fn.dataTableExt.afnSortData['dom-checkbox'] = function  ( oSettings, _, iColumn ) {
+       return $.map( oSettings.oApi._fnGetTrNodes(oSettings), function (tr, i) {
+           return result=$('td:eq('+iColumn+') input', tr).prop('checked') ? '1' : '0';
+       } );
+    }
+
 })(jQuery);
+