WebFX WebBoard
Message Thread:
View All Messages
Back to WebFX
 Sortable table minor bug + enhancement, Erik Dybdahl, April 22, 2003

Subject: Sortable table minor bug + enhancement From: Erik Dybdahl Date: April 22, 2003

The little bug: in the case of Date-columns, empty cell values are not handled.

I also needed to sort Time-columns (on the format "HH:mm"), and added code for this.

But I think this really should be handled in a more generic way.
Say that I needed another date format, eg. "dd-MM-yyyy", I could call this "MyDate", and provide a function that parses the string according to this format, returning the correct date value to the getValueFromString function.
Something like:

function myDateParser(sText)
    var aDate = new Date();
    return aDate.valueOf();
SortableTable.prototype.setFormat("MyDate", myDateParser)

Anyway, below is is the function after being changed to meet my immediate needs.

erik d.

SortableTable.prototype.getValueFromString = function (sText, sType)
 switch (sType)
  case "Number":
   return Number(sText);
  case "CaseInsensitiveString":
   return sText.toUpperCase();
  case "Date":
   var d = new Date(0);
   if (sText && sText.length >= 10)
    var parts = sText.split("-");
    if (parts.length == 3)
     d.setMonth(parts[1] - 1);
   return d.valueOf();
  case "Time":
   var d = new Date();
   if (sText && sText.length >= 1)
    var parts = sText.split(":");
    d.setMinutes(parts.length > 0 ? parts[1] : 0);
   return d.valueOf();
 return sText;




Enter your reply to this message below. HTML tags are not supported but words that start with http://, ftp:// or mailto: are converted to links.

View All Messages
Back to WebFX