I have been trying to sort based on pagetitle. My page titles are in the form "item_name n" where n is a number from 1-15. Sorting on title gives:
item_name 1
item_name 10
item_name 11
item_name 12
item_name 13
item_name 14
item_name 15
item_name 9...
OR, descending
item_name 9
item_name 8...
item_name 7
...
item_name 15
item_name 14
item_name 13...
I set the "description" field for each content item to just the number (1-15). Sorting ascending or descending on the description gives the same result as above.
Does ditto know how to sort numerically? Or am I messed up somehow? (incidentally we are using MySQL client version: 4.1.22, so that sorting problem i keep reading about doesn’t seem to apply).
My ditto call:
[!Ditto&parents=`[*id*]`&display=`all`&tpl=`haseltoniaItem`&sortBy=`description`&sortDir=`DESC`!]
Revo 2.0.8-pl
They’re sorted alphabetically and "15" comes in lower than "9," so the only way it will work is if you make them all the same length with leading zeros ("09" instead of "9") in your titles (or hack the Ditto code to add a sorting function).
I believe Ditto will sort by menuindex if you tell it to, so you could set that manually and get what you want without changing the page titles.
It seems that all ordering in ditto is string ordering. I just set the menu index of each item to the item number, by manipulating the database with phpMyAdmin (because otherwise it was too tedious to do so), and sorted on that. But geez, wouldn’t it be better if ditto treated numbers as, um numbers?
Revo 2.0.8-pl
Why not just put a leading zero or two on the numeric part of the page titles? If they’re generated in code, it should be possible to add the leading zeros automatically.
you can create an extender with custom-sorting for example like this:
<?php
if (!function_exists('customsort'))
{
function customsort($a, $b)
{
$a = substr($a['pagetitle'], 9);
$b = substr($b['pagetitle'], 9);
if ($a == $b)
{
return 0;
}
return ($a < $b)?-1:1;
}
}
$orderBy["custom"][] = array ("pagetitle", "customsort");
$ditto->advSort = true;
?>
I see that Ditto already has a custom sort function (called customSort() ). It uses strnatcmp() so, in theory, it should do what you want automatically.
That’s great, but where’s the documentation? I can’t find any evidence of a customSort parameter, except in the orderBy documentation, which says if you use a custom sort other sorting parameters will not function.
Do I have to pore through source code to understand this snippit?
Why is Ditto so poorly documented? It is too cool to be so hard to use.
Revo 2.0.8-pl
Quote from: drwagner13 at Dec 14, 2008, 05:53 PM
That’s great, but where’s the documentation? I can’t find any evidence of a customSort parameter, except in the orderBy documentation, which says if you use a custom sort other sorting parameters will not function.
Do I have to pore through source code to understand this snippit?
Why is Ditto so poorly documented? It is too cool to be so hard to use.
Ditto does quite a lot of things very well and most are pretty well documented, IMO. Your problem is not a common one and most people would solve it by just using 01, 02, ... 15 for the numbers - adding the leading zero when the number is created, if necessary. If you have to use numbers without a leading zero, I’m afraid you’ll have to be willing to do some coding
This may not seem like a common need, unless your OS already sorts in this human-undersstood fashion (like the Mac OS does).
In my original post I indicated that I want to sort on a title (a sequentially numbered journal title). Obviously, BobRay, I’m not going to put leading zeros in the volume numbers of the title of already-published issues. That would be an absurd way to solve the problem!
Of course coding is fine, and I thank Bruno17 for a useful solution.
In my case I decided to simply sort on the menu order, and I did a very quick SQL insert to set the menu order field equal to the volume number. This workaround makes adding new content an extra step, so I will look to the coding idea for a future upgrade.
In the meantime, I stand by my assertion that Ditto is poorly documented, as I can find no reference to a customSort option anywhere.
Revo 2.0.8-pl