The sortable content of HtmlTable isn't hooked in to the date parsers, I
think. If you look at my example (which is right out of HtmlTable.Sort) it
actually specifies a regex to match against. You might consider opening a
ticket in lighthouse to hook this up to the Date parser.

As for a regex for your date string, you'll just have to muddle through it.
regex isn't fun, but I promise you'll learn something as you attempt it.

One other option: label your columns manually. Here's an example:

HtmlTable.defineParsers({
//A parser to allow lexicographical sorting by any string.
dataSortString: {
 match: /data-sort-string/,
convert: function() {
return this.get('data-sort-string');
 },
number: false
}
});


This would allow for a sort on something like this:

<td data-sort-string="foo">whatever</td>

This custom parser just looks for an explicit value and invokes an explicit
parser. It's a way to skip all the other parsers and use a specific value
with a specific function. It's less flexible, but that's sometimes a good
thing.

On Thu, Feb 10, 2011 at 11:17 AM, hamburger <[email protected]> wrote:

> Thanks Aaron,
> that means i have only to change the match-line?
> isn't it declared in MooTools.lang.setLanguage("de-DE");
>
> on the other hand i am not very familiar with regex. have you got a
> tip  for 31. Januar 2011 - 23:29:07.
>
> thanks a lot
> cheers
>
> On 10 Feb., 20:04, Aaron Newton <[email protected]> wrote:
> > see docs:
> >
> > http://mootools.net/docs/more/Interface/HtmlTable.Sort#HtmlTable:defi...
> >
> > HtmlTable.defineParsers({
> > //this is the default date parser; alter to suit your needs
> > 'custom-date': {
> >  match: /^\d{2}[-\/ ]\d{2}[-\/ ]\d{2,4}$/,
> > convert: function() {
> > var d = Date.parse(this.get('text').stripTags());
> >  return $type(d) == 'date' ? d.format('db') : '';
> >
> > },
> >  type: 'date'
> > }
> > });
> >
> > Note that this is NOT an instance method. Not "myTable.defineParser" -
> it's
> > a static method on the HtmlTable namespace.
> >
> > On Thu, Feb 10, 2011 at 9:07 AM, hamburger <[email protected]> wrote:
> > > sorry, i don't get it
> > > i tried this without any result:
> >
> > > var myTable = new HtmlTable($('theTable'),
> > >        {sortable: true,
> > >         zebra: true,
> > >         classZebra: "zebra",
> > >         classHeadSort:"downArrow",
> > >         classHeadSortRev :"upArrow",
> > >         classCellSort:"focusedColumn"
> > >          });
> >
> > > myTable.sort(0, true, false);
> >
> > > // to parse to: 31. Januar 2011 - 23:29:07
> >
> > > myTable.Parsers = {
> > > 'date': {
> > > match: /^\d{2}[.\/ ]\A[-\/ ]\d{2,4}$/,
> > > convert: function(){
> > > var d = Date.parse(this.get('text').stripTags());
> > > return (typeOf(d) == 'date') ? d.format('db') : '';
> > > },
> > > type: 'date'
> > > }
> > > };
> >
> > > myTable.defineParser = function(parsers){
> > >        myTable.Parsers = Object.append(myTable.Parsers, parsers);
> > >            };
> >
> > > On 10 Feb., 17:28, Aaron Newton <[email protected]> wrote:
> > > > Look in HtmlTable.Sort.js
> >
> > > >
> https://github.com/mootools/mootools-more/blob/master/Source/Interfac...
> >
> > > > There's even a method defined for you to add another:
> >
> > > >
> https://github.com/mootools/mootools-more/blob/master/Source/Interfac...
> >
> > > > Just pass it an object like the others.
> >
> > > > On Thu, Feb 10, 2011 at 6:24 AM, hamburger <[email protected]> wrote:
> > > > > Hello,
> > > > > i have a problem with my table i would like to sort by date.
> > > > > my first collum is a date like  31. Januar 2011 - 23:29:07
> > > > > but it sorts it by 31 not by date.
> > > > > the docs says that it will be sorted by date and it mentiones
> > > > > something by parsers what i do not understand.
> >
> > > > > my code:
> >
> > > > > var myTable = new HtmlTable($('theTable'),
> > > > >        {sortable: true,
> > > > >         zebra: true,
> > > > >         classZebra: "zebra",
> > > > >         classHeadSort:"downArrow",
> > > > >         classHeadSortRev :"upArrow",
> > > > >         classCellSort:"focusedColumn",
> > > > >         });
> >
> > > > > where or how can i add the parser here?
> > > > > thanks for help in advance
>

Reply via email to