I've currently got Table Manager v4.6 which doesn't sort by date
I've tried to find out in the latest version now has this before upgrading. Can anyone confirm this?
If so what would be the date format to use?
Thanks

Comments

pobster’s picture

Nope date sorting isn't implemented in the 4.6 version and as I'm not working on it any more, I'm afraid it'll never be supported... If you want to do it manually just enter the date in the format 'YY-MM-DD' and it should sort properly then.

I've tried to remove the 4.6 version from being downloadable as I don't recommend its use. Unfortunately it doesn't seem to be possible to remove it?

Pobster

martynho’s picture

Can v4.7 sort by date?

pobster’s picture

Yes it can, it 'hides' a sortable formula in a comment and so sorts on that part rather than the date string (which can be set to whatever format you like).

You could possibly use the backport module to use the 4.7 module with Drupal 4.6.x? I don't know whether it'd work or not, but maybe worth trying if you need the functionality.

Thanks

Pobster

martynho’s picture

If I remain with v4.6,
is it possible to "hide" columns?

Currently I create a table per year then enter the date MM.DD & sort on that.
But its not very user friendly e.g. 04.23 is ok if you're American, but I'm not.
I have to therefore add in another column to show an easier to read date e.g. 23-Apr.
It would be good to "hide" the MM.DD column.

pobster’s picture

Nope... Well... Yes... But not as it is currently, you'll need a little magic... As you're not American I will safely assume that you can follow simple instructions;

Replace the tablemanager_sort function with this:

/**
* Comments aren't sortable, so we temporarily alter them to sort on them
*/
function strip_tags_c($string, $allowed_tags = '<!-->') {
  $allow_comments = (strpos($allowed_tags, '<!-->') !== false );
  if ($allow_comments) {
    $string = str_replace(array('<!--', '-->'), array('&lt;!--', '--&gt;'), $string);
    $allowed_tags = str_replace('<!-->', '', $allowed_tags);
  }
  $string = strip_tags($string, $allowed_tags);
  if ($allow_comments) {
    $string = str_replace(array('&lt;!--', '--&gt;'), array('<!--', '-->'), $string);
  }
  return $string;
} // strip_tags_c

/**
* Sort function
*/
function tablemanager_sort(&$data, $field, $sort = "asc") {
  // reduce $field by one as it currently holds human friendly numbering - first column should be 0 not 1
  $next = $field;
  $field--;
  $code = array_key_exists($next, $data) ? "if (0 == (\$cmp = strnatcasecmp(strip_tags_c(\$a['data']['$field']['data']), strip_tags_c(\$b['data']['$field']['data'])))) return strnatcasecmp(strip_tags_c(\$a['data']['$next']['data']), strip_tags_c(\$b['data']['$next']['data'])); else return \$cmp;" : "return strnatcasecmp(strip_tags_c(\$a['data']['$field']['data']), strip_tags_c(\$b['data']['$field']['data']));";
  if ($sort == "asc"){
    uasort($data, create_function('$a,$b', $code));
  }
  else {
    uasort($data, create_function('$b,$a', $code));
  }
  return;
} // tablemanager_sort

Now enter your dates as html comments like this;

<!--yyyy/mm/dd-->7th of November 2006

Now what *should* happen is you'll replicate the functionality of the 4.7 module, note this is untested but only because I can't see any reason why it wouldn't work... What will happen is that the table will be sorted by the comment which will be hidden (because it's a comment!) so whatever is written after it is irrelevant hence you could actually write the months by full name.

Try it and let me know if it works okay, thanks.

Pobster