If one of the columns is not chosen for the Default Sort option, then an error, "o is not defined", is generated by jquery.tablesorter.min.js. This is because the tablesorter function is called with the "sortList" parameter regardless of whether or not the defaultSort is actually set.

If you choose a Default Sort column, the error disappears. This is wouldn't be a huge problem, except any jQuery code called after this will not execute. This is how I noticed the bug; The Admin Menu module would not load on any pages that contained a NodeTable table.

I have included a patch.

--- nodetable.js        2010-09-24 03:57:05.000000000 -0400
+++ nodetable.sort-fix.js       2010-09-24 03:57:31.000000000 -0400
@@ -20,6 +20,15 @@
   // Remove even/odd classes (added by Drupal core) from rows
   // to avoid conflict with the tablesorter plugin.
   $('#' + settings.id + ' tr').removeClass('even odd');
-  $('#' + settings.id).tablesorter({sortList: [[settings.defaultSort, settings.defaultSortOrder]], headers: headersObj, widgets: ['zebra'],  widgetZebra: {css: ['nodetable-odd', 'nodetable-even']}, debug: false});
+
+  // Set default options to for tablesorter
+  var sortOptions = {headers: headersObj, widgets: ['zebra'],  widgetZebra: {css: ['nodetable-odd', 'nodetable-even']}, debug: false};
+
+  // Only append sortList if defaultSort is set
+  if ( settings.defaultSort ) {
+    sortOptions[sortList] = [[settings.defaultSort, settings.defaultSortOrder]];
+  }
+
+  $('#' + settings.id).tablesorter(sortOptions);
 };
CommentFileSizeAuthor
#1 nodetable-sort-fix.patch975 bytesjbova
nodetable-sort-fix.patch934 bytesjbova

Comments

jbova’s picture

Title: Javascript error "o is not defined" if default sort column is not set » Javascript error "o is not defined" if default sort column is not set - patch included
StatusFileSize
new975 bytes

I just realized the patch wasn't in the Drupal community preferred format. I didn't include the function names.

I have attached a new patch. The actual changes to the module are identical in both.

--- nodetable.js        2010-09-24 03:57:05.000000000 -0400
+++ nodetable.sort-fix.js       2010-09-24 03:57:31.000000000 -0400
@@ -20,6 +20,15 @@ Drupal.behaviors.nodeTable = function (c
   // Remove even/odd classes (added by Drupal core) from rows
   // to avoid conflict with the tablesorter plugin.
   $('#' + settings.id + ' tr').removeClass('even odd');
-  $('#' + settings.id).tablesorter({sortList: [[settings.defaultSort, settings.defaultSortOrder]], headers: headersObj, widgets: ['zebra'],  widgetZebra: {css: ['nodetable-odd', 'nodetable-even']}, debug: false});
+
+  // Set default options to for tablesorter
+  var sortOptions = {headers: headersObj, widgets: ['zebra'],  widgetZebra: {css: ['nodetable-odd', 'nodetable-even']}, debug: false};
+
+  // Only append sortList if defaultSort is set
+  if ( settings.defaultSort ) {
+    sortOptions[sortList] = [[settings.defaultSort, settings.defaultSortOrder]];
+  }
+
+  $('#' + settings.id).tablesorter(sortOptions);
 };