After the honeymoon, Tip 1
Category Flex DominoIts been about 2 months since i started using adobe flex in billable anger, and even the best platform looses some of its ability to escape criticism in that time, flex however is proving to be everything that I had hoped for, but you still bump into the odd thing that domino does much better, so I'm doing a series of tips and tricks to help you get everything from both systems (especially when used together).
Todays tip is sortable date columns in flex data grids
Flex data grids are a wonderful thing, with easy sorting and sizeable columns and such, but one thing sucks on them, and that's the fact that they only do TEXT sorting, dates are just treated like text which means that all of the common date formats wont sort correctly, Booooo!, but we can fix that surprisingly easily
First you want to output your date data from notes in YYYYMMDD format, why?? because this formats displays the same when sorted textually or chronologically
so in a view that would be (its a bit long as we need to pad the short days/months (thanks to Ben Poole for pointing this out))
***edited by popular vote to a shorted version***
@Text(@Year(LossDate)) + @Right("0" + @Text(@Month(LossDate));2) + @Right("0" + @Text(@Day(LossDate));2)
if your using a web service to return that value, the Java code would be
import java.util.Date;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
Item dateitem = doc.getFirstItem("DateIWant");
DateTime notesdate = dateitem.getDateTimeValue();
DateFormat dateFormatordered = new SimpleDateFormat("yyyyMMdd");
String UpdDtSort=dateFormatordered.format(notesdate);
if you using lotusscript for you webservice then your on your own!!.
Now into flex and define a "Dateformater", this is my personal fav date format (is it sad that i have one) and produces dates like "Tue May 04 2009", which i find removes many problems with international formats causing confusion.
<mx:DateFormatter id="dateFormatternice" formatString="EEE MMM DD YYYY"/>
Next you will need your actual datagrid (which you will already have if you have discovered this problem).
<mx:DataGrid width="740" height="126" x="10" y="34" id="datesortview" dataProvider="{mynotesview}" fontFamily="Arial">
<mx:columns>
<mx:DataGridColumn headerText="Description" dataField="Desc"/>
<mx:DataGridColumn headerText="Updated Date" dataField="UpdDtSort" labelFunction="dateLabel"/>
</mx:columns>
</mx:DataGrid>
You will notice the "labelFunction" at the end of the date column, that calls the following function (and passes the parameters automatically).
private function dateLabel(item:Object, column: DataGridColumn) : String {
if (item[column.dataField] != null) {
var TempDate:Date = DateField.stringToDate(item[column.dataField], "YYYYMMDD");
return dateFormatternice.format(TempDate);
} else {
return "";
}
}
This basically just takes in each value in the column, converts it to a date using a mask, formats to a pretty format and returns it back to the column. it is MUCH faster than attempting a code based sort solution (as some people use in flex using "sortCompareFunction" on a datagrid).
your column now has 2 values the underlying data format in the happily sortable "20090504" and the label format that the user sees in the format "Tue May 04 2009", yet again a feature we took for granted in notes requires a bit of coding to get it in other platforms.







Comments
On formatting the date with formula, here is a shorter version that I've used:
@Text(@Year(LossDate)) + @Right("0" + @Text(@Month(LossDate));2) + @Right("0" + @Text(@Day(LossDate));2)
Posted by Richard Hogan At 10:51:42 On 04/07/2009 | - Website - |
Posted by mark At 11:54:23 On 04/07/2009 | - Website - |
Currently have about 300 - 400 rows in the datagrid and not seeing any performance hit - not compared to Notes 8.5 anyway
By the way your not mad having a favourite date format, mines DD-MMM-YYYY
Mark
Posted by Mark Barton At 09:22:45 On 09/07/2009 | - Website - |
That is the name of the document regulating the international ISO date format, it is YYYY-MM-DD.
It has the advantage of being alphabetically sortable, more readable than your suggestion, AND a lot of programs will recognise immediately that this is a date (MS Excel comes to mind).
Just my 2 cents
Andrew
Posted by Andrew Magerman At 12:42:54 On 09/07/2009 | - Website - |
Posted by mark At 13:02:58 On 09/07/2009 | - Website - |
Posted by mark At 13:05:53 On 09/07/2009 | - Website - |
I was suggesting ISO as your format for sorting, not the user display format.
In my previous life as a mechanical engineer, I had to struggle with US imperial units. Disaster! We usually converted immediately to SI, did the calculations, then reconverted to US units.
Internationalization tends to be the last thing american programmers do... The number of times I have not been able to fill in an international address because of some silly "Please enter the state you live in" with a dropdown of US States... Duhh
Andrew
Posted by Andrew Magerman At 19:04:16 On 09/07/2009 | - Website - |
Posted by mark At 22:35:54 On 09/07/2009 | - Website - |
[code]String.format("%02d", YOUR_INTEGER_GOES_HERE);[/code]
Smashing (shame about the UBB code not actually, uh, working)
Posted by Ben Poole At 14:19:58 On 21/07/2009 | - Website - |
Posted by dilan hotrey At 10:06:14 On 05/11/2009 | - Website - |